c++ - 断言失败 <dst.data != src.data > in unknown function ../../ocv/opencv/modules/imgproc/src/imgwarp.cpp

标签 c++ c image visual-studio-2010 opencv

嘿,有人可以帮我找到这个错误的解决方案吗:

断言在未知函数中失败../../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 尺寸不正确时,例如零(空垫)或小于功能要求。

你介意在 cv::Mat img = cv::imread("lena.jpg"); 之后检查 img 吗 通过 img.empty() 或通过 imshow 显示 img?

关于c++ - 断言失败 <dst.data != src.data > in unknown function ../../ocv/opencv/modules/imgproc/src/imgwarp.cpp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20681719/

相关文章:

c - dbx:警告:使用 srcline 信息进入函数

C - 编程 HI-LO 游戏

python - 使用 Python 图像库调整透明 png 大小和光晕效果

java - 将 base64 字符串图像显示为超链接

image - 在 MediaLibrary 中保存图像

c++ - C++中的排名树

c++ - 检查类型的所有字段是否为 "primitives"

c++ - 定位涉及线和圆相交的小部件?

`posix_spawn` 的能力

c++ - 使用 C++11 属性