quantumpotato
quantumpotato

Reputation: 9767

Python Import error Opencv NameError: name highgui is not defined

Python 2.7.5

I added the homebrew/science to my brew taps.

I ran

brew install opencv.

bash profile I added

export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

I've opened the headgazer folder and run

python tracker.py


Traceback (most recent call last):
  File "tracker.py", line 21, in <module>
    from roi_detector import ViolaJonesRoi
  File "/Users/username/Downloads/headtracker_version_0.0/roi_detector.py", line 21, in <module>
    import opencv as cv
ImportError: No module named opencv
~/Downloads/headtracker_version_0.0:.

Ok, looks like it's called opencv2. So I swap out occurances of import opencv as cv with

import cv2 as cv

now in viola_jones_opencv.py I have

import cv2 as cv
from cv import *
from cv.highgui import *

And I get an error on importing highgui

ImportError: No module named highgui

Upvotes: 0

Views: 2932

Answers (2)

Dark Leviathan
Dark Leviathan

Reputation: 489

there is no highgui module so I do not know what you ar doing. Also, I agree with berak as renaming anything imported is a pretty bad idea. You just sometimes dont know if there is another directory named the same thing. Good luck on your fix anyways.

Upvotes: 2

berak
berak

Reputation: 39806

there is no highgui module in opencv's python api. (full-stop)

actually , all your import statements look dorky.

(renaming cv2 to cv is a bad idea, since there existed an old cv module before. you're only confusing yourself and others this way)

replace all of them with :

import cv2

and stick with :

cv2.imshow() 
cv2.waitKey()   

etc

[EDIT]

if you're trying to run something like this ,

then there's bad news for you. opencv comes with it's own python bindings since a very long time now, but apart from that, there exist several outdated 3rd party bindings. the code you're trying to run seems to be one of those, so you can't use it with opencv's builtin api.

Upvotes: 2

Related Questions