0

How to read the image through opencv and send it to zxing for detection instead of using the image path?

reader = zxing.BarCodeReader()
qrcode = reader.decode(img_path)

I want to use the code as below, but I won't do it in detail.

reader = zxing.BarCodeReader()
qrcode = reader.decode(cv2.imread(img_path))
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
SunWenkui
  • 1
  • 3
  • which specific library/package of zxing for python do you use? – Christoph Rackwitz Aug 24 '22 at 10:06
  • Does this answer your question? [How can i pass image itself not path of it to zxing library for decode pdf417](https://stackoverflow.com/questions/65790791/how-can-i-pass-image-itself-not-path-of-it-to-zxing-library-for-decode-pdf417) – Christoph Rackwitz Aug 24 '22 at 10:06

1 Answers1

0

zxing supports PIL images so you can try:

qrcode = reader.decode(Image.open(img_path))`

If you need to use opencv images, first convert them to PIL:

qrcode = reader.decode(Image.fromarray(cv2.imread(img_path)))

Or you can write them to a temporary file, what zxing is actually doing if you pass a PIL image.

Links:

Markus
  • 5,976
  • 5
  • 6
  • 21