如何避免cv2.undistort造成的延误?

How to avoid delays caused by cv2.undistort?

我在 python 中使用 OpenCV 来跟踪对象。首先,我应该校准相机,找到属性后我应该找到物体的精确位置,它应该是实时的

我找到了这段代码

ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None)
.
.
.

# undistort
dst = cv2.undistort(img, mtx, dist, None, newcameramtx)

所以根据这段代码我应该不失真每一帧,这很耗时, 有没有办法设置相机的参数,然后使用机器视觉? 或任何其他方式?

undistort 的问题是它每次调用时都会重新计算从失真像素到未失真像素的映射。您只需计算一次坐标变换。您可以使用 cv.initUndistortRectifyMap 计算它,其中 returns 对应的映射(请参阅 documentation here). Then you can use the function cv.remap