如何使用该perspectiveTransform
功能?
运行我的代码时,将产生以下异常:
OpenCV 错误:断言失败(scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F))在perspectiveTransform,文件/Users/donbe/Documents/opencv/opencv/modules/core/src/matmul .cpp,第 1916 行
谁能帮我?
我的代码如下:
Point2f srcTri[4];
Point2f dstTri[4];
Mat warp_mat;
Mat src;
/// Load the image
src = imread( argv[1], 1 );
srcTri[0] = Point2f(0,0);
srcTri[1] = Point2f(src.cols,0);
srcTri[2] = Point2f(src.cols,src.rows);
srcTri[3] = Point2f(0,src.rows);
dstTri[0] = Point2f(0,0);
dstTri[1] = Point2f(src.cols/2,0);
dstTri[2] = Point2f(src.cols/2,src.rows);
dstTri[3] = Point2f(0,src.rows);
warp_mat = getPerspectiveTransform(srcTri, dstTri);
Mat warp_dst(src.size(), src.type());
//There will produce a exception.
perspectiveTransform(src, warp_dst, warp_mat);
namedWindow( "Warp", CV_WINDOW_AUTOSIZE );
imshow( "Warp", warp_dst );
waitKey(0);
return 0;
Run Code Online (Sandbox Code Playgroud)
你检查过你的源图像,它检查了要求吗?
void perspectiveTransform(InputArray src, OutputArray dst, InputArray mtx)
Parameters:
src – Source two-channel or three-channel floating-point array. Each element is a 2D/3D vector to be transformed.
dst – Destination array of the same size and type as src .
mtx – 3x3 or 4x4 floating-point transformation matrix.
Run Code Online (Sandbox Code Playgroud)
笔记:
该函数转换一组稀疏的 2D 或 3D 向量。如果要使用透视变换来变换图像,请使用 warpPerspective() 。
查看文档以获取更多详细信息:http : //opencv.itseez.com/modules/core/doc/operations_on_arrays.html?highlight=perspectivetransform#cv2.perspectiveTransform
希望这可以帮助。
归档时间: |
|
查看次数: |
14081 次 |
最近记录: |