0

I am trying to test to decode a qr code real time using python and openCV 3.0.But now I am getting an error message on my terminal. I tried to search on the internet but I still unable to solve it. Can I know whats the error.

This is my Python code:

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)

This is the error code:

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

This is the traceback message:

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'

Is it the error because of the opencv version? Thank you.

1
  • Now its saying no module named cv Commented Jul 22, 2015 at 7:30

2 Answers 2

0

When you use cv2 you should use

cv2.VideoCapture.read

instead of QueryFrame. For more info see here.
You can try this code

capture = cv.VideoCapture(0)
set_zbar = zbar.ImageScanner()
while True:
    _,frame = capture.read()

Updated

This error message

AttributeError: 'numpy.ndarray' object has no attribute 'width'

you get because that changed the format of the return value. With cv frame was an object with some type, and with cv2 frame is np.ndarray. Instead of width attr you can get its dimensions with shape method. Migration from cv to cv2 is not simple process and requires rewriting of a part of the code.

Sign up to request clarification or add additional context in comments.

13 Comments

well now the error shows inside the scanner_process() . The error now is AttributeError: 'tuple' object has no attribute 'width'
@raaj5671 Return format of capture.read() differ from QueryFrame. Please, check corrected answer
now i am getting this error AttributeError: 'numpy.ndarray' object has no attribute 'width'
i have added the traceback message on my question now
@raaj5671 You trying to add it to my answer. Please, add it to your question
|
0

I solved it by installing the python-opencv package

sudo apt-get install python-opencv

That solved my whole problem. Thanks to kvorobiev for helping me all the way.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.