1

This hour problem is..... Adding a text on the Opencv Webcam Window(live). Let me explain; with this code i open the Webcam using Opencv on Python3.

import cv2
import time

capture = cv2.VideoCapture('Picture Maker')
capture
cap = cv2.VideoCapture(0)

while True:
ret,im = cap.read()
blur = cv2.GaussianBlur(im,(0,0),1)
cv2.imshow('Picture Maker',blur)
cv2.imwrite('MyPic.jpg', blur)
if cv2.waitKey(10) == 27:
    break

The line cv2.imwrite('MyPic.jpg', blur) is there because, the purpose of my program is to give the possibility to take a photo after a determined time ( this is the why of the import time, but i still didn't figured out how to do this after 10 seconds from the opening ).

My question is How to have a text on the window with the live webcam image(video)?? i tried this but doesn't work:

font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(capture,'Count Down',(10,500), font, 4,(255,255,255),2,cv2.LINE_AA)

Or at least i don't know where to put it..

And have you any advice for the countdown?? Greetings Federico

1 Answer 1

3

You should call imshow after all your drawing - putText and imwrite.

Also, to take a picture after given time has passed, you should have a timer initialized outside the loop, and check at each frame whether 10 seconds have passed. You can do it like this:

import time

start_time = time.time()
while True:
    waited = time.time() - start_time
    print('Waited {} seconds'.format(waited))

    if waited >= 10:
        # take pic
        break

Watch out, though, that this is a busy wait.

Not the answer you're looking for? Browse other questions tagged or ask your own question.