miladzzz
miladzzz

Reputation: 13

How to avoid delays caused by cv2.undistort?

I am using OpenCV in python to track an object. first, I should calibrate the camera and after finding the properties I should find the precise location of the object and it should be real-time

I found this code

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

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

so based on this code i should undistort every frame, and it is time-consuming, is there any way to set the parameter of camera and then use the machine vision? or any other way?

Upvotes: 1

Views: 1452

Answers (1)

Ash
Ash

Reputation: 4718

The problem with undistort is that it recomputes the mapping from distorded to undistorted pixels every time it is called. You need to compute the coordinate transform only once. You can just compute it using cv.initUndistortRectifyMap which returns the corresponding mapping (see the documentation here). Then you can use the function cv.remap.

Upvotes: 3

Related Questions