【问题标题】:opencv transform tilt view to plan viewopencv 将倾斜视图转换为平面视图
【发布时间】:2020-08-19 12:50:00
【问题描述】:

这是我用 USB 相机拍摄的照片。我的相机与水平线有一个角度,目标在底部,平行和正交线划定矩形。便利贴是中心矩形的控制标记。

然后我进行了几个分步处理,以调整视图的“倾斜”并提取线条。 这是没有变换的线提取:

{"type":"toGray"} => mat.cvtColor(cv4.COLOR_BGR2GRAY);

{"type":"toBlur","size":10} => mat.gaussianBlur(new cv4.Size(size, size),0);

{"type":"toCanny","low":50,"high":150} => mat.canny(low_threshold, high_threshold);

{"type":"getLines","rho":1,"theta":0.017453292222222222,"threshold":15,"min_line_length":50,"max_line_gap":20 }] => 让 lines = mat. houghLinesP(rho, theta, 阈值, min_line_length, max_line_gap);

结果是:

现在,我想在提取线条之前使用“warpAffine”功能校正视图倾斜。 我选择居中矩形的四个点,以构建两个“三点数组”(src,dst):

matTransf = cv4.getAffineTransform( srcPoints, dstPoints);
resultMat = mat.warpAffine( matTransf, new cv4.Size( mat.cols, mat.rows));

结果如下:

错在哪里?

我也试过了:

// four points at each corner of the rectangle, srcPoints for the  picture, and dstPoints for the theoric shape

// With getPerspectiveTransform
matTransf = cv4.getPerspectiveTransform( srcPoints, dstPoints);
resultMat = mat.warpPerspective( matTransf, new cv4.Size( mat.cols, mat.rows));

// With findHomography
let result = cv4.findHomography( srcPoints, dstPoints);
matTransf = result.homography;
resultMat = mat.warpPerspective( matTransf, new cv4.Size( mat.cols, mat.rows));

结果是:

最好的问候。

【问题讨论】:

    标签: opencv transform


    【解决方案1】:

    变换不是亲和,而是单应性描述的视角。在图像中选择一个物理矩形的四个角,将它们映射到与物理矩形具有相同纵横比的矩形中的点,从中估计单应性(findHomography),最后进行变形(warpPerspective)。

    【讨论】:

    • findHomography 和 getPerspectiveTransform 给出几乎相同的结果。
    • 但也许“将它们映射到与物理点具有相同纵横比的矩形中的点”是我应该研究的方向。
    • 解释来自“结果图像”显示。我的网页显示的是正方形图片,而不是正确的宽度/高度比。 getPerspectiveTransform 和 warpPerspective 函数是不错的函数(4 分)。所以Francesco的建议也不错。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-27
    • 1970-01-01
    • 2022-08-02
    • 2019-12-18
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    相关资源
    最近更新 更多