使用opencv捕获单张图片 [英] Capture single picture with opencv

查看:142
本文介绍了使用opencv捕获单张图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过几个关于使用python和opencv从网络摄像头流捕获帧的事情,但是如何使用python和opencv以指定的分辨率捕获一张图片?

  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)

不要但是知道如何关闭相机。



上述代码的ipython会话示例:

 在[1]中:import cv 

在[2]中:capture = cv.CaptureFromCAM(0)

在[7]中:img = cv.QueryFrame(capture)

在[8]中:print img.height,img.width
480 640

在[9]中:cv.SetCaptureProperty (CA pture,cv.CV_CAP_PROP_FRAME_HEIGHT,480/2)
Out [9]:1

在[10]中:cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_WIDTH,640/2)
Out [10]:1

在[11]中:img = cv.QueryFrame(capture)

在[12]中:print img.height,img.width
240 320


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 opencv?

解决方案

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

这篇关于使用opencv捕获单张图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆