Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: 4 camera Bird's Eye view?

I am having quite a lot of trouble thinking of how to make a four camera bird's eye view like that seen in luxury cars. Here is the original that I will be using as an example for this question...enter image description here

Right now, I have made it so the image is skewed using .getPerspectiveTransform but that is just for one image.

enter image description here

I obviously need four and am clueless on how to stitch those images together. I am also clueless if this is how the images are supposed to look like. Here is the code I currently have:

import cv2 as cv
import numpy as np

img1 = cv.imread("testBird.jpg", cv.IMREAD_COLOR)
image = np.zeros((700, 700, 3), np.uint8)
src = np.array([[0,200],[480,200],[480,360],[0,360]],np.float32)
dst = np.array([[0,0],[480,0],[300,360],[180,360]],np.float32)

M = cv.getPerspectiveTransform(src, dst)
warp = cv.warpPerspective(img1.copy(), M, (480, 360))
cv.imshow('transform', warp)
cv.waitKey(0)
cv.destroyAllWindows()

and here is the end image that I would roughly like to have (A friend put together using Photoshop)...

enter image description here

like image 545
user3818089 Avatar asked Jun 02 '16 21:06

user3818089


1 Answers

To implement the transform, you need to refer to the getPerspectiveTransform function. It takes:

  • src: Coordinates of quadrangle vertices in the source image.
  • dst: Coordinates of the corresponding quadrangle vertices in the destination image.

    I think that it's not an easy problem to define "src" and "dst". It needs some computations based on real-world data and cannot be solved by itself, just by having a look at the pictures.


So for me, the key idea is make a plan of the desired scene (what it must look like). It should use real data such as:

  • the distance between cameras
  • the angle of view of the cameras
  • the size of the rectangle between the cameras (the gray and white grid)

enter image description here

Then you can find a good value for the distance E-F depending on the size of the "viewport of your fictive bird's view camera". After that, your job is nearly done.


The dst parameter is simply a scaled version of the rectangle I J L K (for the upper camera). Depending on the size in pixel of the output image.

The src parameter should be a rectangle in your photograph. Its width will fill the entire picture. The height must be computed from the E-F wanted distance.

enter image description here

They are two ways to compute the height of the red rectangle. Either you place "markers" on the real scene (or you try to detect some) to automatically find a horizontal line. Or, you can try to compute it as a complex function of the elevation angle of your camera (but I want to advise you, I think it seems quite complicated).

Here's how I would have solved that problem. I hope it helped :)

like image 65
Alexis Clarembeau Avatar answered Sep 21 '22 05:09

Alexis Clarembeau