Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from imutils.video import VideoStream
- from pyzbar import pyzbar
- import argparse
- import datetime
- import imutils
- import time
- import cv2
- # construct the argument parser and parse the arguments
- ap = argparse.ArgumentParser()
- ap.add_argument("-i", "--image", required=True, help="path to input image")
- args = vars(ap.parse_args())
- image = cv2.imread(args["image"])
- newimage = cv2.resize(image, (500, 500))
- # find the barcodes in the image and decode each of the barcodes
- barcodes = pyzbar.decode(newimage)
- print (type(barcodes))
- # loop over the detected barcodes
- for barcode in barcodes:
- # extract the bounding box location of the barcode and draw the
- # bounding box surrounding the barcode on the image
- (x, y, w, h) = barcode.rect
- cv2.rectangle(newimage, (x, y), (x + w, y + h), (0, 0, 255), 2)
- # the barcode data is a bytes object so if we want to draw it on
- # our output image we need to convert it to a string first
- print(type(barcode))
- barcodeData = barcode.data.decode("utf-8")
- barcodeType = barcode.type
- # draw the barcode data and barcode type on the image
- text = "{} ({})".format(barcodeData, barcodeType)
- cv2.putText(newimage, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
- 0.5, (0, 0, 255), 2)
- # print the barcode type and data to the terminal
- print("[INFO] Found {} Data: {}".format(barcodeType, barcodeData))
- # show the output image
- cv2.imshow("Image", newimage)
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement