Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. from imutils.video import VideoStream
  2. from pyzbar import pyzbar
  3. import argparse
  4. import datetime
  5. import imutils
  6. import time
  7. import cv2
  8. # construct the argument parser and parse the arguments
  9. ap = argparse.ArgumentParser()
  10. ap.add_argument("-i", "--image", required=True, help="path to input image")
  11. args = vars(ap.parse_args())
  12. image = cv2.imread(args["image"])
  13. newimage = cv2.resize(image, (500, 500))
  14.  
  15. # find the barcodes in the image and decode each of the barcodes
  16. barcodes = pyzbar.decode(newimage)
  17. print (type(barcodes))
  18. # loop over the detected barcodes
  19. for barcode in barcodes:
  20. # extract the bounding box location of the barcode and draw the
  21. # bounding box surrounding the barcode on the image
  22. (x, y, w, h) = barcode.rect
  23. cv2.rectangle(newimage, (x, y), (x + w, y + h), (0, 0, 255), 2)
  24.  
  25. # the barcode data is a bytes object so if we want to draw it on
  26. # our output image we need to convert it to a string first
  27. print(type(barcode))
  28. barcodeData = barcode.data.decode("utf-8")
  29. barcodeType = barcode.type
  30.  
  31. # draw the barcode data and barcode type on the image
  32. text = "{} ({})".format(barcodeData, barcodeType)
  33. cv2.putText(newimage, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
  34. 0.5, (0, 0, 255), 2)
  35.  
  36. # print the barcode type and data to the terminal
  37. print("[INFO] Found {} Data: {}".format(barcodeType, barcodeData))
  38.  
  39. # show the output image
  40. cv2.imshow("Image", newimage)
  41. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement