Closed ThurgaShri closed 2 years ago
Is there any function to do this?
Not presently, but the module could easily be extended to do it using a NamedTemporaryFile.
Yea thanks, got it working by saving it in a temp dir.
img = cv2.imread('image.jpg')
imgOutput = #do something
with tempfile.TemporaryDirectory() as tmpdir:
cv2.imwrite(tmpdir+'/1.jpg', imgOutput)
files_in_dir = os.listdir(tmpdir)
## Image from temp dir
reader = zxing.BarCodeReader()
barcode = reader.decode(tmpdir+'/'+files_in_dir[0])
Yea thanks, got it working by saving it in a temp dir.
Note that your version may be quite slow, because writing as a JPEG involves unnecessary (re)compression, and may be lossy causing some images no longer to work.
What I was suggesting is modifying python-zxing itself to make this a built-in capability. :upside_down_face:
You didn't specify in your original issue what image library you were using… so I assumed PIL Image
class, which is very commonly used in Python modules that manipulate images.. I went ahead and Just Did It, so now zxing.BarCodeReader
will accept the PIL Image class. See 81f55d3e8666ae42178f579353704f8526cd4200
If you want to extend this to work for the OpenCV format, it should be quite easy.
How can I pass an image array to BarcodeReader instead of the filename?
to
Is there any function to do this?