Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
opencv将倾斜视图转换为平面视图_Opencv_Transform - Fatal编程技术网

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

opencv将倾斜视图转换为平面视图,opencv,transform,Opencv,Transform,这是我用USB相机拍的照片。我的相机有一个水平线的角度,目标在底部,平行线和正交线分隔矩形。Post是中心矩形的控制标记 然后,为了调整视图的“倾斜”并提取线,我进行了几步逐步的处理。 以下是不进行变换的直线提取: {“type”:“toGray”}=>mat.cvtColor(cv4.COLOR_bgr2 gray) {“type”:“toBlur”,“size”:10}=>mat.gaussianBlur(新cv4.size(size,size),0) {“type”:“toCanny”

这是我用USB相机拍的照片。我的相机有一个水平线的角度,目标在底部,平行线和正交线分隔矩形。Post是中心矩形的控制标记

然后,为了调整视图的“倾斜”并提取线,我进行了几步逐步的处理。 以下是不进行变换的直线提取:

{“type”:“toGray”}=>mat.cvtColor(cv4.COLOR_bgr2 gray)

{“type”:“toBlur”,“size”:10}=>mat.gaussianBlur(新cv4.size(size,size),0)

{“type”:“toCanny”,“low”:50,“high”:150}=>mat.canny(low_阈值,high_阈值)

{“type”:“getLines”,“rho”:1,“theta”:0.017453292222,“threshold”:15,“minu_line_length”:50,“max_line_gap”:20}]=>让line=mat.houghLinesP(rho,theta,threshold,minu line_length,max_line_gap)

结果是:

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

结果如下:

错在哪里

我也试过:

// 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));
结果是:


致以最诚挚的问候。

转换不是一种亲缘关系,它是由单应性描述的透视图。在图像中选择物理矩形的四个角,将它们映射到与物理矩形具有相同纵横比的矩形中的点,从它们估计单应性(FindHomeography),最后扭曲(warpPerspective).

findHomography和getPerspectiveTransform给出了几乎相同的结果。但也许“将它们映射到矩形中与物理点具有相同纵横比的点”是我应该研究的方向。解释来自“结果图像”显示。我的网页显示的是一个正方形的图片,而不是正确的宽度/高度比。getPerspectiveTransform和warpPerspective函数是很好的函数(有4个点)。所以弗朗西斯科的建议也很好。
// 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));