opencv将倾斜视图转换为平面视图

问题描述

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

original view

point of view

然后,我将逐步处理一些步骤,以调整视图的“倾斜”并提取线条。 这是没有变换的行提取:

{“ 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}] =>让线=垫子。 houghLinesP(rho,theta,threshold,min_line_length,max_line_gap);

结果是:

result 1

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

transformation scheme

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

结果如下:

final result

哪里出错了?

我也尝试过:

// 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,mat.rows));

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

结果是:

findHomograhy and getPerspectiveTransform

最诚挚的问候。

解决方法

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...