Capture single picture with opencv

后端 未结 3 2347
迷失自我
迷失自我 2021-02-20 10:20

I have seen several things about capturing frames from a webcam stream using python and opencv, But how do you capture only one picture at a specified resolution with python and

3条回答
  •  你的背包
    2021-02-20 11:01

    Use SetCaptureProperty :

    import cv
    capture = cv.CaptureFromCAM(0)
    cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, my_height)
    cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, my_width)
    cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FORMAT, cv.IPL_DEPTH_32F)
    
    img = cv.QueryFrame(capture)
    

    Do not know how to close the camera, though.

    Example of a ipython session with the above code :

    In [1]: import cv
    
    In [2]: capture = cv.CaptureFromCAM(0)
    
    In [7]: img = cv.QueryFrame(capture)
    
    In [8]: print img.height, img.width
    480 640
    
    In [9]: cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 480/2)
    Out[9]: 1
    
    In [10]: cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, 640/2)
    Out[10]: 1
    
    In [11]: img = cv.QueryFrame(capture)
    
    In [12]: print img.height, img.width
    240 320
    

提交回复
热议问题