1

I want to capture frame from my camera when the specific event occurs

my code

    import cv2
    cap = cv2.VideoCapture("http://192.168.43.1:8080/video") 
    if int(data) < 45:
        return_value, image = cap.read()
        cv2.imwrite('Images/'+str(count)+'.png', image)
        print("capture")

But its saving older frames when it capture please help i want current frame to be saved

2
  • 1
    What is data? how are you handling the "event"? Commented Sep 8, 2021 at 13:02
  • Data is data coming from COM port from ultrasonic distance sensor and if distance is less then 45 I have to capture image Commented Sep 8, 2021 at 16:45

1 Answer 1

2

You need to read the frames as they arrive otherwise they just buffer up. You discard the frames you don't want. The following should demonstrate this:

import cv2
cap = cv2.VideoCapture("http://192.168.43.1:8080/video") 
while True:
    return_value, image = cap.read()
    k = cv2.waitKey(10) & 0xFF
    if int(data) < 45:
        cv2.imwrite('Images/'+str(count)+'.png', image)
        print("capture")
    if k == ord('q'):
        break
Sign up to request clarification or add additional context in comments.

1 Comment

No its not working its capturing older frames

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.