我正在使用 openCv 2.4.6。
以下不起作用:
cv::Mat src = cv::imread(argv[1], 1);
int x11 = src.rows/3; int y11 = src.cols/3;
int x12 = src.rows/3; int y12 = src.rows*2/3;
int x13 = src.cols*2/3; int y13 = src.rows*2/3;
int x21 = 0; int y21 = 0;
int x22 = 0; int y22 = src.rows-1;
int x23 = src.cols-1; int y23 = src.rows-1;
#if 1 // doesn't work
float src_tri_data[] = {x11, y11, 0, x12, y12, 0, x13, y13, 0};
cv::Mat src_tri(3, 2, CV_32F, src_tri_data, 3*sizeof(float));
float dst_tri_data[] = {x21, y21, 0, x22, y22, 0, x23, y23, 0};
cv::Mat dst_tri(3, 2, CV_32F, dst_tri_data, 3*sizeof(float));
#else // works
float src_tri_data[] = {x11, y11, x12, y12, x13, y13};
cv::Mat src_tri(3, 2, CV_32F, src_tri_data, 2*sizeof(float));
float dst_tri_data[] = {x21, y21, x22, y22, x23, y23};
cv::Mat dst_tri(3, 2, CV_32F, dst_tri_data, 2*sizeof(float));
#endif
cv::Mat trans = cv::getAffineTransform(src_tri, dst_tri);
它因断言而失败:
OpenCV 错误:断言失败 (src.checkVector(2, CV_32F) == 3 && dst.checkVector(2, CV_32F) == 3) 在未知函数,文件 C:\slave\builds\WinInstallerMegaPack\src\opencv\modules\ imgproc\src\imgwarp.cpp,第 3612 行
但是,如果我使矩阵连续,它就可以工作。知道为什么吗?