在未知函数中Assert< dst.data!= src.data>失败../../ocv/opencv/modules/imgproc/src/imgwarp.cpp

8iwquhpp  于 2023-10-16  发布在  其他
关注(0)|答案(4)|浏览(129)

请问有没有人可以帮我解决这个错误:
在未知函数中Assert失败../../ocv/opencv/modules/imgproc/src/imgwarp.cpp
我试着编译这个链接中存在的代码:http://ipwithopencv.googlecode.com/svn/trunk/ThinPlateSpline/ThinPlateSpline/
我使用2个类和主要的:
下面是我的主要代码:

  1. #include "stdafx.h"
  2. #include <cv.h>
  3. #include <cxcore.h>
  4. #include <highgui.h>
  5. #include "CThinPlateSpline.h"
  6. #include "iostream"
  7. using namespace std;
  8. int _tmain(int argc, _TCHAR* argv[])
  9. {
  10. // load a nice picture
  11. cv::Mat img = cv::imread("lena.jpg");
  12. // generate some generic points
  13. // usually you would use a interest point detector such as SURF or SIFT
  14. std::vector<cv::Point> iP, iiP;
  15. // push some points into the vector for the source image
  16. iP.push_back(cv::Point(50,50));
  17. iP.push_back(cv::Point(400,50));
  18. iP.push_back(cv::Point(50,400));
  19. iP.push_back(cv::Point(400,400));
  20. iP.push_back(cv::Point(256,256));
  21. iP.push_back(cv::Point(150,256));
  22. // push some point into the vector for the dst image
  23. iiP.push_back(cv::Point(70,70));
  24. iiP.push_back(cv::Point(430,60));
  25. iiP.push_back(cv::Point(60,410));
  26. iiP.push_back(cv::Point(430,420));
  27. iiP.push_back(cv::Point(220,280));
  28. iiP.push_back(cv::Point(180,240));
  29. // create thin plate spline object and put the vectors into the constructor
  30. CThinPlateSpline tps(iP,iiP);
  31. // warp the image to dst
  32. Mat dst;
  33. tps.warpImage(img,dst,0.01,INTER_CUBIC,BACK_WARP);
  34. // show images
  35. cv::imshow("original",img);
  36. cv::imshow("distorted",dst);
  37. //cv::waitKey(0);
  38. //Sleep(5);
  39. cv::waitKey(5000);
  40. return 0;
  41. }

下面是imagewarp方法:

  1. void CThinPlateSpline::warpImage(const Mat& src, Mat& dst, float lambda, const int interpolation,const TPS_INTERPOLATION tpsInter)
  2. {
  3. Size size = src.size();
  4. dst = Mat(size,src.type());
  5. // only compute the coefficients new if they weren't already computed
  6. // or there had been changes to the points
  7. if(tpsInter == BACK_WARP && !FLAG_COEFFS_BACK_WARP_SET)
  8. {
  9. computeSplineCoeffs(pSrc,pDst,lambda,tpsInter);
  10. }
  11. else if(tpsInter == FORWARD_WARP && !FLAG_COEFFS_FORWARD_WARP_SET)
  12. {
  13. computeSplineCoeffs(pSrc,pDst,lambda,tpsInter);
  14. }
  15. computeMaps(size,mapx,mapy);
  16. remap(src,dst,mapx,mapy,interpolation);
  17. }

还有其他类存在于链接中也CthinPlateSpline.cpp和CthinPlateSpline.h..

mm5n2pyu

mm5n2pyu1#

OpenCV中的“Assert失败”通常发生在输入Mat的大小不正确时,例如:零(空垫)或小于功能要求。
您是否介意通过img.empty()检查cv::Mat img = cv::imread("lena.jpg");后的img或通过imshow显示img?

ds97pgxw

ds97pgxw2#

我可以用OpenCV 2.4.7在我的Mac上运行这些
结果图像是一个扭曲的镜头
我只是改变了两个地方如下
首先,我将main.cpp中的包含文件更改为

  1. #include <opencv2/opencv.hpp>
  2. #include "CThinPlateSpline.h"
  3. #include <iostream>
  4. #include <vector>

并将文件包含在CThinPlateSpline.cpp中,以成为

  1. #include <vector>
  2. #include <opencv2/opencv.hpp>
  3. #include "CThinPlateSpline.h"

我只使用3个文件main.cpp、CThinPlateSpline.cpp和CThinPlateSpline.h
链接的库包括

  • loanav_imgproc -loanav_core -loanav_highgui
展开查看全部
ux6nzvsh

ux6nzvsh3#

验证图像是否正确加载。在我的情况下(OpenCV for Python),我的图像根本没有加载。
试着验证你传递给函数的到底是什么图像。

dz6r00yl

dz6r00yl4#

在C++中,当源图像和目标图像没有保存大小时会发生这种情况。在python中,它通常发生在源图像为空,无等时。

相关问题