2017-12-25 15 views
-1
import zbar 
import Image 
import cv2 

# create a reader 
scanner = zbar.ImageScanner() 
# configure the reader 
scanner.parse_config('enable') 
#create video capture feed 
cap = cv2.VideoCapture(0) 

while(True): 
    ret, cv = cap.read() 
    cv = cv2.cvtColor(cv, cv2.COLOR_BGR2GRAY) 
    pil = Image.fromarray(cv) 
    width, height = pil.size 
    raw = pil.tostring() 
    # wrap image data 
    image = zbar.Image(width, height, 'Y800', raw) 

    # scan the image for barcodes 
    scanner.scan(image) 

    # extract results 
    for symbol in image: 
     # do something useful with results 
     print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data 

# clean up 
print "/n ...Done" 

는이 코드를 실행하지만 그것은 기능을 image.tostring으로 무엇을 의미하는지 몰라이 오류 OpenCV의 zbar 파이썬 스캐너 오류

Traceback (most recent call last): 
    File "/home/joeydash/Desktop/InterIIT-UAV-challenge/zbar/main.py", line 17, in <module> 
    raw = pil.tostring() 
    File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 695, in tostring 
    "Please call tobytes() instead.") 
Exception: tostring() has been removed. Please call tobytes() instead. 

을 보여줍니다. 이 문제를 어떻게 해결할 수 있습니까?

+5

예외 사항에 대해 말씀해 주시겠습니까? tostring()'''을'''tobytes()'''와 바꾸십시오. –

답변

1

제이의 코멘트를 표시하는 모든 크레딧. 코드는이 도움이 raw = pil.tobytes()

희망을 줄 raw = pil.tostring() 이 변경되었습니다 방법이

import zbar 
import Image 
import cv2 

# create a reader 
scanner = zbar.ImageScanner() 
# configure the reader 
scanner.parse_config('enable') 
#create video capture feed 
cap = cv2.VideoCapture(0) 

while(True): 
    ret, cv = cap.read() 
    cv = cv2.cvtColor(cv, cv2.COLOR_BGR2GRAY) 
    pil = Image.fromarray(cv) 
    width, height = pil.size 
    raw = pil.tobytes() 
    # wrap image data 
    image = zbar.Image(width, height, 'Y800', raw) 

    # scan the image for barcodes 
    scanner.scan(image) 

    # extract results 
    for symbol in image: 
     # do something useful with results 
     print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data 

# clean up 
print "/n ...Done" 

공지 사항처럼 보일 것입니다!