Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animated codes support suggestion #118

Open
Sami32 opened this issue Nov 1, 2022 · 4 comments
Open

Animated codes support suggestion #118

Sami32 opened this issue Nov 1, 2022 · 4 comments

Comments

@Sami32
Copy link

Sami32 commented Nov 1, 2022

Hello there!

Your great SDK analyse each frame independently so it cannot handle such animated marketing appealing codes:

sequence-01

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 :-/

@yushulx
Copy link

yushulx commented Nov 2, 2022

@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)

image

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.

image

@Keillion
Copy link
Collaborator

Keillion commented Nov 2, 2022

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

@Sami32
Copy link
Author

Sami32 commented Nov 2, 2022

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.

@Keillion
Copy link
Collaborator

Keillion commented Nov 3, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants