Open Sami32 opened 2 years ago
@Sami32 although Dynamsoft Barcode Reader does not support animated GIF, you can do some image processing yourself to make it work.
Here is my code using Dynamsoft Barcode Reader Python edition and OpenCV. If the first frame is undetectable, you can merge the following images with bitwise AND operator until the merged image can be detectable.
pip install dbr opencv-python
from dbr import *
import imageio
import cv2 as cv
image = "test.gif"
gif = imageio.mimread(image)
nums = len(gif)
print("Total {} frames in the gif!".format(nums))
# convert form RGB to BGR
imgs = [cv.cvtColor(img, cv.COLOR_RGB2BGR) for img in gif]
BarcodeReader.init_license("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
reader = BarcodeReader()
def decodeFrame(frame):
try:
results = reader.decode_buffer(frame)
index = 0
if results != None:
for result in results:
points = result.localization_result.localization_points
print("Barcode Index: " + str(index) + "\n")
print("Barcode format: " + result.barcode_format_string + '\n')
print("Barcode value: " + result.barcode_text + '\n')
print("Bounding box: " + str(points[0]) + ' ' + str(points[1]) + ' ' + str(points[2]) + ' ' + str(points[3]) + '\n')
print('-----------------------------------\n')
index += 1
return results
except BarcodeReaderError as error:
print(error)
return None
# Try first frame
merged = imgs[0]
results = decodeFrame(imgs[0])
if (results == None):
# merge frames until detectable
i = 1
while i < nums:
print("Frame {}".format(i))
frame = imgs[i]
cv.imshow("frame", frame)
merged = cv.bitwise_and(merged, imgs[i])
cv.imshow("merged", merged)
# Decode merged frame
results = decodeFrame(merged)
if results != None:
break
i += 1
cv.waitKey(0)
Barcode format: QR_CODE
Barcode value: http://www.epikinnovations.com
Bounding box: (51, 9) (270, 9) (269, 227) (51, 228)
You can get a better merged image with more frames.
https://github.com/dynamsoft-rd-0/dbrjs-mass-samples/tree/master/mergeGif
Sample of merging gif.
Test directly: https://dynamsoft-rd-0.github.io/dbrjs-mass-samples/mergeGif/merge-gif.html
Thank you very much to both of you for your help +1
Feel free to close this issue if it doesn't fit your SDK library development roadmap.
I will consider better support for animated gifs. We can keep this issue utill we solve it.
As for video format, we do support them. BarcodeScanner.videoSrc.
Hello there!
Your great SDK analyse each frame independently so it cannot handle such animated marketing appealing codes:
Such codes could be packaged in an animated GIF, AVIF or a video format. My suggestion is to add an option to treat each frame as a part of the same code.
I apology for my weak english :-/