Ask Your Question
0

Create mock OpenCV camera on Python

asked May 5 '0

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.

Preview: (hide)

2 answers

Sort by » oldest newest most voted
1

answered May 6 '0

berak gravatar image

updated May 6 '0

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")
Preview: (hide)
1

answered May 5 '0

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().

Preview: (hide)

Question Tools

1 follower

Stats

Asked: May 5 '0

Seen: 3,215 times

Last updated: May 06 '20