嘿,请有人帮我找到这个错误的解决方案:
在未知函数中断言失败../../ 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 ...我真的需要帮助,抱歉我的英文不好
答案 0 :(得分:1)
当输入 Mat 的大小不正确时,OpenCV中的“断言失败”通常会发生,例如零(空Mat)或小于函数的要求。
您是否介意在cv::Mat img = cv::imread("lena.jpg");
之后检查 img
通过img.empty()或imshow显示img?
答案 1 :(得分:0)
我可以使用OpenCV 2.4.7在我的Mac上运行它们
结果图像是扭曲的lena
我只是改变了两个地方,如下所示
首先,我将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
答案 2 :(得分:0)
验证图像是否正确加载。就我而言(Python 的 OpenCV)我的图像根本没有加载。
尝试验证您传递给函数的究竟是什么图像。