opencv 将倾斜视图转换为平面视图
opencv transform tilt view to plan view
这是我用 USB 相机拍的照片。我的相机与水平线成一定角度,目标在底部,平行线和正交线分隔矩形。 Post-它是中心矩形的控制标记。
然后为了调整视图的'tilt'和提取线条,我进行了几个分步处理。
这是没有转换的线提取:
{"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, threshold, min_line_length, max_line_gap);
结果是:
现在,我想在提取线条之前使用 'warpAffine' 函数校正视图的倾斜度。
我select四个点的居中矩形,依次构建两个“三点数组”(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));
结果是:
此致。
变换不是亲和力,是单应性描述的视角。 Select 在图像中物理矩形的四个角,将它们映射到与物理矩形具有相同纵横比的矩形中的点,从它们估计单应性(findHomography),最后扭曲(warpPerspective)。
这是我用 USB 相机拍的照片。我的相机与水平线成一定角度,目标在底部,平行线和正交线分隔矩形。 Post-它是中心矩形的控制标记。
然后为了调整视图的'tilt'和提取线条,我进行了几个分步处理。 这是没有转换的线提取:
{"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, threshold, min_line_length, max_line_gap);
结果是:
现在,我想在提取线条之前使用 'warpAffine' 函数校正视图的倾斜度。
我select四个点的居中矩形,依次构建两个“三点数组”(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));
结果是:
此致。
变换不是亲和力,是单应性描述的视角。 Select 在图像中物理矩形的四个角,将它们映射到与物理矩形具有相同纵横比的矩形中的点,从它们估计单应性(findHomography),最后扭曲(warpPerspective)。