[英]opencv - Assertion failed (dst.data == dst0.data) in cvCvtColor
[英]Assertion failed <dst.data != src.data > in unknown function ../../ocv/opencv/modules/imgproc/src/imgwarp.cpp
嘿,請有人幫我找到這個錯誤的解決方案:
斷言在未知函數 ../../ocv/opencv/modules/imgproc/src/imgwarp.cpp 中失敗
我嘗試編譯此鏈接中存在的代碼: http : //ipwithopencv.googlecode.com/svn/trunk/ThinPlateSpline/ThinPlateSpline/
我使用 2 個類和主要的:
這是我的主要代碼:
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include "CThinPlateSpline.h"
#include "iostream"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
// load a nice picture
cv::Mat img = cv::imread("lena.jpg");
// generate some generic points
// usually you would use a interest point detector such as SURF or SIFT
std::vector<cv::Point> iP, iiP;
// push some points into the vector for the source image
iP.push_back(cv::Point(50,50));
iP.push_back(cv::Point(400,50));
iP.push_back(cv::Point(50,400));
iP.push_back(cv::Point(400,400));
iP.push_back(cv::Point(256,256));
iP.push_back(cv::Point(150,256));
// push some point into the vector for the dst image
iiP.push_back(cv::Point(70,70));
iiP.push_back(cv::Point(430,60));
iiP.push_back(cv::Point(60,410));
iiP.push_back(cv::Point(430,420));
iiP.push_back(cv::Point(220,280));
iiP.push_back(cv::Point(180,240));
// create thin plate spline object and put the vectors into the constructor
CThinPlateSpline tps(iP,iiP);
// warp the image to dst
Mat dst;
tps.warpImage(img,dst,0.01,INTER_CUBIC,BACK_WARP);
// show images
cv::imshow("original",img);
cv::imshow("distorted",dst);
//cv::waitKey(0);
//Sleep(5);
cv::waitKey(5000);
return 0;
}
這是 imagewarp 方法:
void CThinPlateSpline::warpImage(const Mat& src, Mat& dst, float lambda, const int interpolation,const TPS_INTERPOLATION tpsInter)
{
Size size = src.size();
dst = Mat(size,src.type());
// only compute the coefficients new if they weren't already computed
// or there had been changes to the points
if(tpsInter == BACK_WARP && !FLAG_COEFFS_BACK_WARP_SET)
{
computeSplineCoeffs(pSrc,pDst,lambda,tpsInter);
}
else if(tpsInter == FORWARD_WARP && !FLAG_COEFFS_FORWARD_WARP_SET)
{
computeSplineCoeffs(pSrc,pDst,lambda,tpsInter);
}
computeMaps(size,mapx,mapy);
remap(src,dst,mapx,mapy,interpolation);
}
鏈接中還有其他類 CthinPlateSpline.cpp 和 CthinPlateSpline.h ...請我真的需要幫助,為我的英語不好而抱歉
OpenCV 中的“斷言失敗”通常發生在您輸入的Mat大小不正確時,例如零(空 Mat)或小於函數的要求。
你介意在cv::Mat img = cv::imread("lena.jpg");
之后檢查img嗎? 通過 img.empty() 還是通過 imshow 顯示 img?
我可以使用 OpenCV 2.4.7 在我的 Mac 上運行這些
結果圖像是扭曲的莉娜
我只是改變了兩個地方如下
首先,我將main.cpp中包含的文件改成
#include <opencv2/opencv.hpp>
#include "CThinPlateSpline.h"
#include <iostream>
#include <vector>
並包含在 CThinPlateSpline.cpp 中的文件成為
#include <vector>
#include <opencv2/opencv.hpp>
#include "CThinPlateSpline.h"
我只使用了 3 個文件 main.cpp、CThinPlateSpline.cpp 和 CThinPlateSpline.h
鏈接的庫是
-lopencv_imgproc -lopencv_core -lopencv_highgui
驗證圖像是否正確加載。 在我的情況下(Python 的 OpenCV)我的圖像根本沒有加載。
嘗試驗證您傳遞給函數的究竟是什么圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.