Ask Your Question
0

AttributeError: 'module' object has no attribute 'CAP_PROP_FRAME_HEIGHT'

asked 2017-11-02 03:48:39 -0600

Xenoshell gravatar image

updated 2017-11-02 07:05:16 -0600

So i am using OpenCv 3.3, python 2.7 and PyQt and i get this Attribute Error which i have no idea how to fix. This is my Code:

import numpy as np
import cv2
import sys
sys.path.append('/home/pi/.virtualenvs/cv/lib/python2.7/site-packages/usr/local/lib/python2.7/site-packages')

cap = cv2.VideoCapture(0)

while(True):
        ret, frame = cap.read()

cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
    # Display the resulting frame
    cv2.imshow('frame',frame)
    cv2.namedWindow('frame', cv2.CV_WINDOW_AUTOSIZE)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break#Display resulting frame

#when everything done, release the capture
cap.release()
cv2.destroyAllWindows()

If it makes any difference i used a virtual enviroment to install OpenCv and i also tried to use CV_CAP_PROP_FRAME_HEIGHT but it also didnt get recognized and returns the same error.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-11-02 07:27:29 -0600

supra56 gravatar image
import cv2

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)

cv2.namedWindow('frame', cv2.WINDOW_AUTOSIZE)
while(True):
    ret, frame = cap.read()

    # Display the resulting frame
    cv2.imshow('frame',frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break#Display resulting frame

#when everything done, release the capture
cap.release()
cv2.destroyAllWindows()
edit flag offensive delete link more

Comments

@Xenoshell. I test it on RPI3, You can't put cap.set outside of while block and then cv2.imshow inside while block. I also correct for you.... cv2.WINDOW_AUTOSIZE.
I am using OpenCv 3.3.1

supra56 gravatar imagesupra56 ( 2017-11-02 07:34:13 -0600 )edit

You can't put cap.set outside of while block and then cv2.imshow inside while block Thats what you did in your code. Anyway i tried it but the error is still there. Im starting to think that my opencv is not really working

    File "selfwritten.py", line 8, in <module>
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
AttributeError: 'module' object has no attribute 'CAP_PROP_FRAME_HEIGHT'

Shouldnt there be cv2 instead of 'module' ?

Xenoshell gravatar imageXenoshell ( 2017-11-02 09:58:01 -0600 )edit

No! You will have to upgrading to python 3.5. Btw, Did you used my code as above?

supra56 gravatar imagesupra56 ( 2017-11-02 10:48:23 -0600 )edit

Really?? I have to use python 3.5? But i compiled cv2 for python2. I am gonna deinstall opencv and install it for python3 again if i have to but i would rather not

Xenoshell gravatar imageXenoshell ( 2017-11-06 02:00:05 -0600 )edit
0

answered 2017-11-02 03:52:27 -0600

berak gravatar image

updated 2017-11-02 03:53:15 -0600

use cv2.CAP_PROP_FRAME_HEIGHT

(the old CV_ prefixed constants were all removed 2.4 -> 3.x)

(help(cv2) (and scroll down to the bottom) will show you the constants)

edit flag offensive delete link more

Comments

well i already tried that. Still same error.

Xenoshell gravatar imageXenoshell ( 2017-11-02 04:01:24 -0600 )edit

are you sure, it's using opencv3.3 ? (cv2.__version__)

berak gravatar imageberak ( 2017-11-02 04:05:03 -0600 )edit

I used this tutorial to install OpenCv3 on my raspberry pi: https://www.pyimagesearch.com/2017/09...

    source ~/.profile 
 workon cv
 python
>>> import cv2
>>> cv2.__version__

Executing this in the terminal returns '3.3.0' so i guess i am in version 3.3.0. What could be the problem is that i installed OpenCV in a virutal enviroment and that could be the reason it wont get recognized. Also thanks for the fast answers

Xenoshell gravatar imageXenoshell ( 2017-11-02 04:10:27 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-11-02 03:48:39 -0600

Seen: 7,778 times

Last updated: Nov 02 '17