基于目标检测的OpenCV鱼眼镜头去畸变问题
鱼眼镜头目标检测的畸变校正问题
我使用鱼眼镜头开展目标检测以最大化视场角(FOV),目前已实现图像去畸变代码,但重投影误差(2.9像素)表现不佳,且图像边缘严重失真。校准过程采用8×11规格的棋盘格(含7×10内角点),并在多个平面采集了大量图像。
相关代码
import os import glob import cv2 as cv import numpy as np def calibrate(showPics=True): # Read Image root = os.getcwd() calibrationDir = os.path.join(root,'snapshots//') imgPathList = glob.glob(os.path.join(calibrationDir,'*.jpg')) # Initialize nRows = 7 nCols = 10 termCriteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER,30,0.001) worldPtsCur = np.zeros((nRows*nCols,3), np.float32) worldPtsCur[:,:2] = np.mgrid[0:nRows,0:nCols].T.reshape(-1,2) worldPtsList = [] imgPtsList = [] # Find Corners for curImgPath in imgPathList: imgBGR = cv.imread(curImgPath) imgGray = cv.cvtColor(imgBGR, cv.COLOR_BGR2GRAY) cornersFound, cornersOrg = cv.findChessboardCorners(imgGray,(nRows,nCols), None) if cornersFound == True: worldPtsList.append(worldPtsCur) cornersRefined = cv.cornerSubPix(imgGray,cornersOrg,(11,11),(-1,-1),termCriteria) imgPtsList.append(cornersRefined) if showPics: cv.drawChessboardCorners(imgBGR,(nRows,nCols),cornersRefined,cornersFound) cv.imshow('Chessboard', imgBGR) cv.waitKey(500) cv.destroyAllWindows() # Calibrate repError,camMatrix,distCoeff,rvecs,tvecs = cv.calibrateCamera(worldPtsList, imgPtsList, imgGray.shape[::-1],None,None) print('Camera Matrix:\n',camMatrix) print('distCoeff',distCoeff) print("Reproj Error (pixels): {:.4f}".format(repError)) return camMatrix,distCoeff def removeDistortion(camMatrix,distCoeff): root = os.getcwd() imgPath = os.path.join(root,'snapshots//snapshot_20240310_153742.jpg') img = cv.imread(imgPath) height,width = img.shape[:2] camMatrixNew,roi = cv.getOptimalNewCameraMatrix(camMatrix,distCoeff,(width,height),1,(width,height)) imgUndist = cv.undistort(img,camMatrix,distCoeff,None,camMatrixNew)
去畸变效果
校正后的图像边缘仍存在严重失真,未达到理想效果,重投影误差处于较高水平。
内容的提问来源于stack exchange,提问作者Luke
相关产品推荐
相关产品推荐

