【问题标题】:Assertion failed <dst.data != src.data > in unknown function ../../ocv/opencv/modules/imgproc/src/imgwarp.cpp断言失败 <dst.data != src.data > 在未知函数 ../../ocv/opencv/modules/imgproc/src/imgwarp.cpp
【发布时间】:2014-01-08 00:32:55
【问题描述】:

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

未知函数中的断言失败../../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 ...请我真的需要帮助,对不起我的英语不好

【问题讨论】:

  • 您显示的代码与问题无关。请挖出 tps.warpImage() 的 src
  • link 这里是 ThinPlateSplace.cpp 所有定义方法都存在的地方
  • 哦,请改为编辑您的问题,使其更具可读性;)
  • 啊,对不起,我已经发布了方法,请查看您是否检测到错误
  • 您使用的图片是否至少为 430X420 像素?

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


【解决方案1】:

OpenCV 中的“断言失败”通常发生在您输入的 Mat 大小不正确时,例如零(空 Mat)或小于函数要求。

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

【讨论】:

  • 感谢 maythe4thbewithu 我在 cv::Mat img = cv::imread("lena.jpg");这个: if(img.empty()==true){ std::cout
  • @younestheboss 我可以在我的 Mac 上使用 OpenCV 2.4.7 运行这些(main.cpp、CThinPlateSpline.cpp、CThinPlateSpline.h),结果图像是扭曲的 Lena。
  • 我正在使用 opencv2.2 我总是遇到同样的问题我尝试更改图像的位置但仍然有同样的错误@maythe4thbewithu 非常感谢您的帮助
  • 你应该使用Windows下图片的完整路径 imread("C:\\where\\is\\your\\lena.jpg") ;注意:有两个\\不是一个\
  • 我要下线30分钟,把你的结果或问题放上来。
【解决方案2】:

我可以在我的 Mac 上使用 OpenCV 2.4.7 运行这些

结果图像是扭曲的 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

【讨论】:

  • 终于成功了亲爱的@maythe4thbewithu 我非常感谢你帮助我
  • 那么路径有什么问题?
  • 抱歉,亲爱的 maythe4thbewithu 一直没有回答,问题出在我在 Visual Studio 中混合发布和调试库的库
【解决方案3】:

验证图像是否正确加载。在我的情况下(Python 的 OpenCV)我的图像根本没有加载。

尝试验证您传递给函数的确切图像。

【讨论】:

    猜你喜欢
    • 2014-01-16
    • 2021-11-28
    • 1970-01-01
    • 2020-08-11
    • 2011-09-28
    • 2016-10-12
    • 2015-09-26
    • 1970-01-01
    • 2018-05-15
    相关资源
    最近更新 更多