我一直在尝试使用opencv 3.1.0 Shape Tranformation类变形图像。具体来说,薄板线算法
(我实际上尝试了Shape Transformers and Interfaces OpenCV3.0中的代码块)
但是问题是,我一直在用控制台说“ getting runtime time error”
D:\ Project \ TPS_Transformation \ x64 \ Debug \ TPS_Transformation.exe(进程13776)已退出,代码为-1073741819
我发现导致错误的代码是
tps->estimateTransformation(source, target, matches);
这是第一次执行转换算法的部分。
我搜索了运行时错误,指出可能是dll问题,但一般来说运行opencv都没有问题。运行形状转换算法(特别是estimateTranformation
函数)时出现错误。
#include <iostream>
#include <opencv2\opencv.hpp>
#include <opencv2\imgproc.hpp>
#include "opencv2\shape\shape_transformer.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat img1 = imread("D:\\Project\\library\\opencv_3.1.0\\sources\\samples\\data\\graf1.png");
std::vector<cv::Point2f> sourcePoints, targetPoints;
sourcePoints.push_back(cv::Point2f(0, 0));
sourcePoints.push_back(cv::Point2f(399, 0));
sourcePoints.push_back(cv::Point2f(0, 399));
sourcePoints.push_back(cv::Point2f(399, 399));
targetPoints.push_back(cv::Point2f(100, 0));
targetPoints.push_back(cv::Point2f(399, 0));
targetPoints.push_back(cv::Point2f(0, 399));
targetPoints.push_back(cv::Point2f(399, 399));
Mat source(sourcePoints, CV_32FC1);
Mat target(targetPoints, CV_32FC1);
Mat respic, resmat;
std::vector<cv::DMatch> matches;
for (unsigned int i = 0; i < sourcePoints.size(); i++)
matches.push_back(cv::DMatch(i, i, 0));
Ptr<ThinPlateSplineShapeTransformer> tps = createThinPlateSplineShapeTransformer(0);
tps->estimateTransformation(source, target, matches);
std::vector<cv::Point2f> transPoints;
tps->applyTransformation(source, target);
cout << "sourcePoints = " << endl << " " << sourcePoints << endl << endl;
cout << "targetPoints = " << endl << " " << targetPoints << endl << endl;
//cout << "transPos = " << endl << " " << transPoints << endl << endl;
cout << img1.size() << endl;
imshow("img1", img1); // Just to see if I have a good picture
tps->warpImage(img1, respic);
imshow("Tranformed", respic); //Always completley grey ?
waitKey(0);
return 0;
}
我只希望能够运行算法,以便可以检查它是否是我想要的算法。
请帮助。
谢谢。
opencv-version 3.1.0
IDE:Visual Studio 2015
操作系统:Windows 10
答案 0 :(得分:1)
尝试添加
transpose(source, source);
transpose(target, target);
在估算Transformation()之前。
请参见https://answers.opencv.org/question/69384/shape-transformers-and-interfaces/。