Camera angles with OpenCV

Tags

, , , , , , , , , , , , ,

‘Just do me Bullet Time,’ Arkwood pleaded, ‘like Keanu in The Matrix.’

It was yet another pathetic attempt to woo Daphne, the plump spotty girl who works down the chippy. If only she could eyeball him in extreme slow motion, dodging bullets, she’d surely leap into his twiggy arms.

I dismissed the idea. ‘I don’t have the equipment,’ I replied curtly. But it did get me thinking what I might do with four webcams and some Python code.

First up, I constructed a camera rig out of a pizza box. Two webcams were plugged into the USB slots at the front of my PC, and two webcams were plugged into the USB slots at the rear of my PC (plugging all four webcams into the front of my PC resulted in read errors).

cameraangles_webcam_rig

Now for a dash of Python code, to read a frame from each of our four webcams:

video_capture = cv2.VideoCapture(device)
current_frame = video_capture.read()[1]

I am using OpenCV Video Capture to grab a webcam image. The device variable is the number of the webcam i.e. 0, 1, 2 or 3.

Here’s our four webcam images, all snapped at the same moment in time…

Front webcam:
cameraangles_webcam_front

Right webcam:
cameraangles_webcam_right

Rear webcam:
cameraangles_webcam_back

Left webcam:
cameraangles_webcam_left

Terrific.

If we let the four webcams roll, we can capture our subject – who happens to be The Dude, from the film The Big Lebowski – at four angles simultaneously. Perhaps our subject will start to dance or smoke a fine cigar. We can switch our point of view during each frame of animation e.g. panning round at 0, 90, 180 and 270 degrees.

I have used OpenGL to render the four camera angles onto a cube…

Front-right of cube:
cameraangles_cube_front_right

Rear-left of cube:
cameraangles_cube_back_left

‘It’s not exactly Bullet Time,’ Arkwood scoffed.

No, it is not. But it’s not too bad for a bit of Python code and a single PC.

Ciao!

P.S. if you want to know how to put animation on a cube, check out my post Display video using OpenGL.

Follow

Get every new post delivered to your Inbox.

Join 89 other followers