Displaying a webcam feed using OpenCV and Python

前端 未结 6 1532
闹比i
闹比i 2020-11-27 11:31

I have been trying to create a simple program with Python which uses OpenCV to get a video feed from my webcam and display it on the screen.

I know I am partly there

6条回答
  •  死守一世寂寞
    2020-11-27 11:43

    Try the following. It is simple, but I haven't figured out a graceful way to exit yet.

    import cv2.cv as cv
    import time
    
    cv.NamedWindow("camera", 0)
    
    capture = cv.CaptureFromCAM(0)
    
    while True:
        img = cv.QueryFrame(capture)
        cv.ShowImage("camera", img)
        if cv.WaitKey(10) == 27:
            break
    cv.DestroyAllWindows()
    

提交回复
热议问题