将代码从 openCV 更新到 openCV2 [英] Updating code from openCV to openCV2

查看:67
本文介绍了将代码从 openCV 更新到 openCV2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些代码从 openCV 更新到 Python 中的 openCV2.原代码如下:

I'm trying to update some code from openCV to openCV2 in python. The original code is as follows:

self.capture = cv.CaptureFromCAM(0)
cv.SetCaptureProperty( self.capture, cv.CV_CAP_PROP_FRAME_WIDTH, 160 );
cv.SetCaptureProperty( self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 120 );

我为 openCV2 编写的代码是这样的:

The code that I wrote for openCV2 is this:

self.capture = cv2.VideoCapture(0)
cv2.VideoCapture.set( CV_CAP_PROP_FRAME_WIDTH, 160 );
cv2.VideoCapture.set( CV_CAP_PROP_FRAME_HEIGHT, 120 );

但是这不起作用我收到一条错误消息:

However this does not work I'm getting an error that says:

cv2.VideoCapture.set( CV_CAP_PROP_FRAME_WIDTH, 160 );AttributeError: 'builtin_function_or_method' 对象没有属性 'set'

cv2.VideoCapture.set( CV_CAP_PROP_FRAME_WIDTH, 160 ); AttributeError: 'builtin_function_or_method' object has no attribute 'set'

推荐答案

试试这个.它会起作用.

Try this one. It will work.

self.capture.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 160)

这篇关于将代码从 openCV 更新到 openCV2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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