Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating code from openCV to openCV2

Tags:

python

opencv

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 );

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' object has no attribute 'set'

like image 619
Will Jones Avatar asked Jun 26 '15 15:06

Will Jones


1 Answers

I removed .cv.CV_, and it worked.

Change:

cv2.cv.CV_CAP_PROP_FRAME_HEIGHT

to:

cv2.CAP_PROP_FRAME_HEIGHT
like image 180
Shitanshu Avatar answered Oct 07 '22 19:10

Shitanshu