0

I'm using Python to try and make a software that just displays a picture of the user, as a test. I do this using Open CV with the following code:

import cv2 as cv

cam = cv.VideoCapture(0)
result, image = cam.read()
cv.imshow("USER", image)
cv.waitKey(1000)
cv.destroyWindow("USER")

The image displays correctly, but it always uses the image from the previous run. I cannot figure out why this is.

I've browsed the internet and stackoverflow, but no similar issues could be found. Any help would be extraordinary.

jmh
  • 43
  • 5

1 Answers1

1

Maybe your camera is buffering more than one frame per shot, according to this post on the OpenCV forum due to poor lighting conditions some cameras could compensate increasing the exposure to more than one frame, you could try the solution on this post: OpenCV VideoCapture lag due to the capture buffer and limit the buffer of the camera. Also you should release the camera before the program ends with cam.release().

A possible solution with this considerations:

import cv2 as cv

cam = cv.VideoCapture(0)
cam.set(cv.CAP_PROP_BUFFERSIZE, 1)
result, image = cam.read()
if(result):
    cv.imshow("USER", image)
    cv.waitKey(1000)
    cv.destroyWindow("USER")

cam.release()

  • I tried, and it worked for the first three captures or so. After that, it lost functionality. – jmh Aug 23 '23 at 23:33
  • Hi, could you provide more details about your case ? On what OS are you working? Python/OpenCV versions? Are you using a virtualenv? What camera are you using? How are you running the code (On the python interpreter o command line)? – Mauricio Aravena Aug 24 '23 at 20:26
  • Sorry about that! I'm working with Windows OS, using Python version 3.11.5. I use OpenCV version 4.8.0. I use PyCharm CE, which I believe comes with a venv, but I am not 100% sure. I use a Nexigo webcam, which is my main camera. I run the code on PowerShell using the `python ` command. Hope that is enough. Thanks for helping me try to fix this! – jmh Aug 24 '23 at 22:53