Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17447

How to close a cv2 window within a Flet program?

$
0
0

The webcam window doesn't seem to close when any key is pressed including the "ESC" key?

Here is an excerpt from the Flet app:

cap = cv2.VideoCapture(0)def main(page : ft.Page):    page.title = "fletCam"    def update_images():        while(cap.isOpened()):            # Capture frame-by-frame            ret, frame = cap.read()            if ret == True:                # encode the resulting frame                jpg_img = cv2.imencode('.jpg', frame)                b64_string = base64.b64encode(jpg_img[1]).decode('utf-8')                image_box.src_base64 = b64_string                page.update()                k = cv2.waitKey(0) & 0xFF        if k == 27:  # close on ESC key            cv2.destroyAllWindows()            else:                break            time.sleep(1/115)        cap.release()        cv2.destroyAllWindows()

I'm running this application on Windows 11


Viewing all articles
Browse latest Browse all 17447

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>