user3597742
user3597742

Reputation: 31

Taking a snapshot from webcam during using the camera in anther function

I am using the camera to detect cars 24/7 using Python, Opencv and a normal usb webcam. In order to take a snapshot I made a function to call it when needed

def SendPic () :
    capture = cv.CaptureFromCAM(0)
    img = cv.QueryFrame(capture)
    cv.SaveImage('pic.jpg', img)

It works fine when used alone but when used inside my code this error comes up

libv4l1: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT

And the image is not saved or even captured

How to take this snapshot without stopping the camera from detecting the cars? What command can I use to stop the camera to take a capture and then return to its main function?

Upvotes: 0

Views: 326

Answers (1)

morynicz
morynicz

Reputation: 2342

If I was You, I'd make the part taking pictures a separate module, and make the car detection module and snapshot module call to the first one using mutexes. You cannot have two separate entities controlling the same hardware piece.

Upvotes: 1

Related Questions