initUndistortRectifyMap

initUndistortRectifyMap

another test method would be to use a whiteboard with known angles points and estimate the error by comparing with experimental results, but I don't know how to set up such a system推荐答案关于您的第一个问题,使主要点偏离图像中心是正常的.估计点是零仰角和方位角,是使径向畸变系数最小的点,对于低值广角镜头(例如,典型的网络摄像头),可以很容易地将其关闭.Regarding your first concern, it is normal to have the principal point off the image center. The estimated point, which is the point of zero elevation and azimuth, is the one that minimizes the radial distortion coefficients, and for a low value wide angle lens (e.g., that of a typical webcam) it can be easily off by noticeable amount.您的校准应该可以满足calibrateCamera的要求.但是,在您的代码段中,您似乎忽略了失真系数.缺少的是initUndistortRectifyMap,如果需要的话,它还可以使主点居中.Your calibration should be ok up to the call to calibrateCamera. However, in your code snippet it seems your ignoring the distortion coefficients. What is missing is initUndistortRectifyMap, which lets you also re-center the principal point if that matters.h, w = img.shape[:2]# compute new camera matrix with central principal pointnew_mtx,roi = cv2.getOptimalNewCameraMatrix(mtx,disto_coef,(w,h),1,(w,h))print(new_mtx)# compute undistort mapsmapx,mapy = cv2.initUndistortRectifyMap(mtx,disto_coef,None,new_mtx,(w,h),5)从本质上讲,它使焦距在两个维度上均等,并使中心点居中(有关参数,请参见OpenCV python文档).It essentially makes focal length equal in both dimensions and centers the principal point (see OpenCV python documentation for parameters).然后,每个_, img = cap.read()您必须在渲染之前使图像不失真you must undistort the image before rendering# apply the remapimg = cv2.remap(img,mapx,mapy,cv2.INTER_LINEAR)# crop the imagex,y,w,h = roiimg = img[y:y+h, x:x+w]在这里,我将背景设置为绿色以强调桶形失真.输出可能是这样的(出于隐私原因,摄像机图像被棋盘代替了):here, I put background to green to emphasize the barrel distortion. The output could be something like this (camera image replaced by checkerboard for privacy reasons):如果执行所有这些操作,则您的校准目标是准确的,并且校准样本会占据整个图像区域,您应该对计算非常有信心.但是,为了验证相对于未失真图像的像素读数测得的方位角和仰角,我可能建议从镜头的第一个主点和在相机正前方以垂直角度放置的校准板开始进行卷尺测量.在那里,您可以计算期望的角度并进行比较.If you do all these, your calibration target is accurate and your calibration samples fill the entire image area you should be quite confident of the computation. However, to validate the measured azimuth and elevation with respect to the undistorted image's pixel readings, I'd maybe suggest tape measure from the lenses first principal point and a calibration plate placed in normal angle right in front of the camera. There you can compute the expected angles and compare.希望这会有所帮助. 这篇关于相机校准,将像素反向投影到方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-26 00:18