我有一个简单的代码,如下所述:
import cv
from opencv.cv import *
from opencv.highgui import *
img = cv.LoadImage("test.jpg")
cap = cv.CreateCameraCapture(0)
while cv.WaitKey(1) != 10:
img = cv.QueryFrame(cap)
cv.ShowImage("cam view", img)
cascade = cv.LoadHaarClassifierCascade('haarcascade_frontalface_alt.xml', cv.Size(1,1))
但我面对这个错误:
# AttributeError: 'module' object has no attribute 'LoadImage'
当我将代码更改为以下内容时:
import cv
#from opencv.cv import *
#from opencv.highgui import *
img = cv.LoadImage("test.jpg")
cap = cv.CreateCameraCapture(0)
while cv.WaitKey(1) != 10:
img = cv.QueryFrame(cap)
cv.ShowImage("cam view", img)
cascade = cv.LoadHaarClassifierCascade('haarcascade_frontalface_alt.xml', cv.Size(1,1))
现在第一个错误得到了解决,另一个错误又出现了。
AttributeError: 'module' object has no attribute 'LoadHaarClassifierCascade'
我需要这两个模块,但似乎他们有冲突得到她。
现在我该怎么办?
你怎样才能拿到你进口的东西?
@有关python中的模块和导入的详细信息,请参见python modules。
如果您可以提供哪些类包含在哪个模块中,我可以为您的问题添加特定的解决方案。
在OpenCV中加载haar分类器(无论如何在python接口中)只需使用cv.load。
请参阅示例here。
而且,OpenCV源代码附带的示例非常好(在
OpenCV-2.xx/samples/python
)。相关问题 更多 >
编程相关推荐