我試圖測試解碼二進制代碼實時使用python和openCV 3.0。但現在我收到我的終端錯誤消息。我試圖在互聯網上搜索,但我仍然無法解決它。我可以知道錯誤是什麼。AttributeError:'模塊'對象沒有屬性'QueryFrame'
這是我的Python代碼:
import cv2 as cv
import zbar
def scanner_procces(frame,set_zbar):
set_width = 100.0/100
set_height = 90.0/100
coord_x = int(frame.width * (1 - set_width)/2)
coord_y = int(frame.height * (1 - set_height)/2)
width = int(frame.width * set_width)
height = int(frame.height * set_height)
get_sub = cv.GetSubRect(frame, (coord_x+1, coord_y+1, width-1, height-1))
cv.Rectangle(frame, (coord_x, coord_y), (coord_x + width, coord_y + height), (255,0,0))
cm_im = cv.CreateImage((get_sub.width, get_sub.height), cv.IPL_DEPTH_8U, 1)
cv.ConvertImage(get_sub, cm_im)
image = zbar.Image(cm_im.width, cm_im.height, 'Y800', cm_im.tostring())
set_zbar.scan(image)
for symbol in image:
print '\033[1;32mResult : %s symbol "%s" \033[1;m' % (symbol.type,symbol.data)
cv.ShowImage("webcam", frame)
cv.WaitKey(10)
if __name__ == "__main__":
cv.namedWindow("webcam", cv.WINDOW_AUTOSIZE)
capture = cv.VideoCapture(0)
set_zbar = zbar.ImageScanner()
while True:
frame = cv.QueryFrame(capture)
scanner_procces(frame,set_zbar)
這是錯誤代碼:
AttributeError: 'module' object has no attribute 'QueryFrame'
這是回溯消息:
init done
opengl support available
select timeout
Traceback (most recent call last):
File "realtimetestwebcam.py", line 38, in <module>
scanner_procces(frame,set_zbar)
File "realtimetestwebcam.py", line 9, in scanner_procces
coord_x = int(frame.width * (1 - set_width)/2)
AttributeError: 'numpy.ndarray' object has no attribute 'width'
是不是因爲的錯誤opencv版本?謝謝。
現在,它說沒有模塊名爲CV – raaj5671