下面链接中的示例findHomography用于获取两组点之间的转换。我想限制转换中使用的自由度,所以想findHomography用estimateRigidTransform.
下面我estimateRigidTransform用来获取物体和场景点之间的转换。objPoints并由scePoints表示vector <Point2f>。
Mat H = estimateRigidTransform(objPoints, scePoints, false);
按照上面教程中使用的方法,我想使用 transformation 转换角值H。本教程使用perspectiveTransform返回的 3x3 矩阵findHomography。使用刚性变换,它只返回一个 2x3 矩阵,因此不能使用此方法。
我将如何转换角的值,vector <Point2f>用这个 2x3 矩阵表示。我只是希望执行与教程相同的功能,但转换的自由度较低。我也看过其他方法,例如warpAffineand getPerspectiveTransform,但到目前为止还没有找到解决方案。
编辑:
我已经尝试过 David Nilosek 的建议。下面我将额外的行添加到矩阵中。
Mat row = (Mat_<double>(1,3) << 0, 0, 1);
H.push_back(row);
但是,这在使用 perspectiveTransform 时会出现此错误。
OpenCV Error: Assertion failed (mtype == type0 || (CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0)) in create, file /Users/cgray/Downloads/opencv-2.4.6/modules/core/src/matrix.cpp, line 1486
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/cgray/Downloads/opencv-2.4.6/modules/core/src/matrix.cpp:1486: error: (-215) mtype == type0 || (CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0) in function create
ChronoTrigger 建议使用warpAffine. 我正在调用warpAffine下面的方法, 1 x 5 的大小是objCornersand的大小sceCorners。
warpAffine(objCorners, sceCorners, H, Size(1,4));
这给出了下面的错误,这表明错误的类型。objCorners并代表 4 个角sceCorners。vector <Point2f>我认为warpAffine会接受Mat可以解释错误的图像。
OpenCV Error: Assertion failed ((M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 2 && M0.cols == 3) in warpAffine, file /Users/cgray/Downloads/opencv-2.4.6/modules/imgproc/src/imgwarp.cpp, line 3280