Ask Your Question

Revision history [back]

Create mock OpenCV camera on Python

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.