Ask Your Question
0

Create mock OpenCV camera on Python

asked 2020-05-05 11:21:31 -0600

eri0o gravatar image

Hi,

I want to write tests for a python program that is using OpenCV.

Essentially it is using dlib to recognize a face area. The program loads and uses this:

import cv2
cap = cv2.VideoCapture(0)

What I want is instead of opening a real video camera, I want to replace cap with a identical video source that is instead made of repeating playing images from a folder (fake/cam_01.jpg, fake/cam_02.jpg, ...) with a defined interval (say 100mS).

With this I can prepare some directories that have test images and I can test the same exact code. How do I do this?

The other catch is half the people in the development team use Windows and half Linux, so I want something that can work on both, preferentially using python without depending on external platform specific tools. I want to run these stuff in a test.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2020-05-06 01:07:22 -0600

berak gravatar image

updated 2020-05-06 01:07:47 -0600

VideoCapture has an internal backend, which allows you to read numbered image sequences,

just pass the 1st imgname like:

 cap = cv2.VideoCapture("fake/cam_01.jpg")
edit flag offensive delete link more
1

answered 2020-05-05 14:36:48 -0600

mvuori gravatar image

Don't worry about VideoCapture. What you seem to need is jut a read() that return an image by some logic. Perhaps just going through a directory one by one in the first iteration, and after the code works, keeping time and giving an image based on that (filenane = prefix + elapsed tine). All the functionaly is just generic programming augmented with imread().

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-05-05 11:20:49 -0600

Seen: 2,869 times

Last updated: May 06 '20