从扭曲的图像返回原始坐标

时间:2013-07-24 08:42:15

标签: c++ opencv

我从图像中提取了四个角,

std::vector<cv::Point2f> ecken;
ecken.push_back(corners[0]);
ecken.push_back(corners[size.height-1]);
ecken.push_back(corners[size.area()-size.height-1]);
ecken.push_back(corners[size.area()-1]);

他们被歪曲成第二张图片:

quad_pts.push_back(cv::Point2f(0, 0));
            quad_pts.push_back(cv::Point2f(quad.cols, 0));
            quad_pts.push_back(cv::Point2f(quad.cols, quad.rows));
            quad_pts.push_back(cv::Point2f(0, quad.rows));

        // Get transformation matrix
            cv::Mat transmtx = cv::getPerspectiveTransform(ecken, quad_pts);
cv::warpPerspective(src, quad, transmtx, quad.size(),1);

我想回到原来的四合一图像,这些是我尝试过的:

cv::Mat trans  = cv::getPerspectiveTransform(quad_pts,ecken );
        cv::perspectiveTransform(quad,test,trans); /// I'm not sure that this correct and the program crashes here

这里是控制台中的错误消息:

OpenCV Error: Assertion failed (scn + 1 == m.cols && (depth == CV_32F || depth =
= CV_64F)) in unknown function, file ..\..\..\opencv\modules\core\src\matmul.cpp
, line 1926

它没有用!! 任何的想法 ??

1 个答案:

答案 0 :(得分:0)

你的两个Mat物体的深度不同。通过打印Mat.depth()来检查两者是否具有相同的图像类型。可能是其中一个是灰度,另一个是颜色。