薄板样条形状变换运行时错误 [退出,代码 -1073741819]
Posted
技术标签:
【中文标题】薄板样条形状变换运行时错误 [退出,代码 -1073741819]【英文标题】:Thin Plate Spline shape transformation run-time error [exited with code -1073741819] 【发布时间】:2019-04-08 09:48:38 【问题描述】:我一直在尝试使用 opencv 3.1.0、Shape Tranformation 类扭曲图像。具体来说,就是薄板Sline算法
(我实际上尝试了Shape Transformers and Interfaces OpenCV3.0的一段代码)
但问题是我一直在控制台说运行时错误
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 版本 3.1.0
IDE:Visual Studio 2015
操作系统:Windows 10
【问题讨论】:
【参考方案1】:尝试添加
transpose(source, source);
transpose(target, target);
在estimateTransformation()之前。
见https://answers.opencv.org/question/69384/shape-transformers-and-interfaces/。
【讨论】:
以上是关于薄板样条形状变换运行时错误 [退出,代码 -1073741819]的主要内容,如果未能解决你的问题,请参考以下文章