print(“ barCode is%s”%textData)TabError:缩进中的制表符和空格使用不一致

问题描述 投票:-1回答:1

我没有问题所在!!!这是错误文件“ c:\ BarCodeReader-master \ barcode_scanner.py”,第44行打印(“条形码是%s”%textData)^TabError:缩进中的制表符和空格不一致使用

from pyzbar import pyzbar
import argparse
import datetime
from datetime import datetime
import imutils
import time
import cv2
import winsound
import pandas as pd 

frequency = 2500  # Set Frequency To 2500 Hertz
duration = 60  # Set Duration To 1000 ms == 1 second


ap = argparse.ArgumentParser()
ap.add_argument("-o", "--output", type=str, default="barcodesData.csv",
    help="path to output CSV file ")
args = vars(ap.parse_args())


print("Starting webcam")

vs = VideoStream(src=0).start()
time.sleep(2.0)
csvWrite = open(args["output"], "w")
found = set()
while True:
    frameData = vs.read()
    frameData = imutils.resize(frameData, width=600)
    barcodes = pyzbar.decode(frameData)
    for barcode in barcodes:
        (x, y, width, height) = barcode.rect
        cv2.rectangle(frameData, (x, y), (x + width, y + height), (0, 0, 255), 2)
        barcodeData = barcode.data.decode("utf-8")
        barcodeType = barcode.type
        textData = "{} ({})".format(barcodeData, barcodeType)

        cv2.putText(frameData, textData, (x, y - 10), 
        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) 
        print("barCode is %s"%textData)



    cv2.imshow("Barcode Scanner", frameData)
    key = cv2.waitKey(1) & 0xFF
    if key == ord("e"):
        break ```


python python-3.x zbar
1个回答
0
投票

您收到的错误是由于line 43line 42末尾的缩进。有未使用的导入,语法错误和缩进问题。

更干净的代码将防止此类错误:

from pyzbar import pyzbar
import argparse
import datetime # Unused import
from datetime import datetime # Unused import
import imutils
import time
import cv2
import winsound # Unused import
import pandas as pd # Unused import


frequency = 2500  # Set Frequency To 2500 Hertz
duration = 60  # Set Duration To 1000 ms == 1 second


ap = argparse.ArgumentParser()
ap.add_argument(
    "-o", 
    "--output", 
    type=str, 
    default="barcodesData.csv",
    help="path to output CSV file "
)
args = vars(ap.parse_args())


print("Starting webcam")

vs = VideoStream(src=0).start()
time.sleep(2.0)
csvWrite = open(args["output"], "w")
found = set()
while True:
    frameData = vs.read()
    frameData = imutils.resize(frameData, width=600)
    barcodes = pyzbar.decode(frameData)
    for barcode in barcodes:
        (x, y, width, height) = barcode.rect
        cv2.rectangle(frameData, (x, y), (x + width, y + height), (0, 0, 255), 2)
        barcodeData = barcode.data.decode("utf-8")
        barcodeType = barcode.type
        textData = "{} ({})".format(barcodeData, barcodeType)

        cv2.putText(
            frameData,
            textData,
            (x, y - 10),
            cv2.FONT_HERSHEY_SIMPLEX,
            0.5,
            (0, 0, 255),
            2
        )
        print("barCode is %s" %textData)


    cv2.imshow("Barcode Scanner", frameData)
    key = cv2.waitKey(1) & 0xFF
    if key == ord("e"):
        break

© www.soinside.com 2019 - 2024. All rights reserved.