# Is it possible to hack camera calibration without having access to the camera?

Many times we have a stream of video to process without access to camera. Having access to camera matrix would be beneficial for various processing techniques. Is it possible to hack camera calibration without having access to the camera?

I have a stream of video from a single camera mounted on a moving car recording the road (Hence multiple parallel lines on the ground plane, corners from lane markers but no circles). I want to create a top-down view of this but I do not have access to the camera. Is it possible? If so how?

I understand from Learning OpenCV: Computer Vision with the OpenCV Library book that I need the following matrices:

1. Intrinsics, and
2. Distortion

.. to cv2.undistort() the image, compute homography cv2.getPerspectiveTransform() and cv2.warpPerspective() to finally get the topview.

Question

1. How can I compute/approximate/guess Intrinsics or Distortion Matrices/parameters? Are all parameters important?
2. Would it be okay to copy parameters from other cameras (like OpenCV source code samples)?

Prior Research:

• OpenCV Python Camera Calibration Tutorial - Requires Access to the Camera
• Camera AutoCalibration - Gives hope "calibration may be obtained if multiple sets of parallel lines or objects with a known shape (e.g. circular) are identified"
• Attempting to understand camera calibration related answers[1][2][3] on SO trying to find answers to my problem.

Update 1: Perspective Transform Experiment

I had attempted using getPerspectiveTransform(pts1,pts2) and dst = cv2.warpPerspective(img,M,(x,y), flags=flags) to match four points of input image to get a sort of top-down view. But I am not sure how to handle the distortions:

Selecting Points: First, I zoomed in on the input and tried to precisely select matching exterior points on the lane markers to create the Homography Matrix and previewed the perspective transformed image with warpPerspective. I saw the lanes were distorted but didn't know how bad. To get an idea I chose points further out by delta (50px) flat on each end. This is what I get:

Can I fix the distortions without having access to the camera? Is there any other way to fix this.

Few input images to play with:

Update 2: Non-Parallel (Scattered) Optical Flow in Top-Down View

Is this due to distortion or something else?:

If I understand correctly, you don't need the intrinsics or extrinsics to achieve that, if a top-down view is all you want. You could basically define 4 points on your parallel lines and then warp the entire image into a canonical view (say $\{\{0,0\}, \{480,960\}\}$).

To do that in OpenCV, all you need to do is compute the homography using findHomography as described here. Then, use warpPerspective (look here) to warp your images.

The only thing you need to care about is the selection of the dimensions of the fronto-parallel view that you are after. It should more or less match the aspect ratio of the original image region.

Regarding the second part of your question: Yes. First of all, let me remind you that many works such as this choose to ignore the distortion estimation. But, I can think of two ways to accomplish that:

1. Use the road lanes itself to correct the distortion: In the fronto-parallel view, create another perspective warp so that the lanes themselves would be vertical. In this setting, think about the lane lines as the vanishing lines in the image (as in a perspective view, they always do). From that, you can even calibrate your camera. Look here, here and here for example.

2. The cars should be following more or less a straight/smooth trajectory. If you compute the motion of all the cars, they should give you similar motions, parallel to the lanes. That information is again useful in constraining and generating a transformation, which would warp your image to a reduced distortion one.

• Thanks @tbirdal: (0) "ignore the distortion estimation" -- I have achieved fair results with this. See update 2 (1) The papers do seem very useful. However, it might take me a while before I can fully understand them and respond back. (2) "[cars] should give you similar motions, parallel to the lanes" -- Nice idea! But I am getting a scattered (non-parallel) optical flow on the lanes, even in the top-down view (see update 2); Need to figure out how to workaround this. – Manav Kataria Jan 18 '15 at 1:33
• It is tough to compute the optical flow of the lanes, as they don't move very often. Edge tracking approaches would be better I guess. (Such as moving edges etc. or even active contours) – Tolga Birdal Jan 18 '15 at 1:41
• I have a video stream where the camera is mounted on the front of a moving vehicle. Hence the lanes markers move with every frame (exception: a lane-end marker which is continuous "---", not "- - -" dashed). – Manav Kataria Jan 18 '15 at 1:48