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

decoding from camera is too slow and non robust #98

Open
denizsincar29 opened this issue Sep 26, 2023 · 1 comment
Open

decoding from camera is too slow and non robust #98

denizsincar29 opened this issue Sep 26, 2023 · 1 comment

Comments

@denizsincar29
Copy link

Hello. I tryed this code and it seams to be very slow. using pygame camera and libdmtx to decode datamatrix, i got 2 scans in second and it doesn't decode properly.

import glob
import os
from time import sleep, time
import pygame
import pygame.camera
from pylibdmtx.pylibdmtx import decode
from PIL import Image

pygame.init()
size=(640, 480)

gameDisplay = pygame.display.set_mode(size)  # 640 480

pygame.mixer.init()
globals().update({os.path.splitext(os.path.basename(i))[0]: pygame.mixer.Sound(i) for i in glob.glob("audio/*.wav")})
success.play()  # sound
pygame.camera.init()
cam = pygame.camera.Camera(0, size, "")
cam.start()
while True:
    img = cam.get_image()
    gameDisplay.blit(img,(0,0))
    
    arr=Image.frombytes("RGB", (img.get_width(), img.get_height()), pygame.image.tobytes(img,"RGB"))
    decinfo=decode(arr)
    if len(decinfo)>0: print(decinfo[0])
    pygame.display.update()
    for event in pygame.event.get() :
        if event.type == pygame.QUIT :
            cam.stop()
            pygame.quit()
            exit()
    dong.play()  # sound playing
    sleep(0.05)
@phlibi
Copy link

phlibi commented Oct 24, 2023

I found that there is a huge speedup by telling the library to look for at most one code using decode(arr, max_count=1). Further speed gains may be possible by downsampling the image prior to decoding.

Concerning the robustness, I've found an even illumination and a proper quiet zone to be very important for successful decoding.

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

2 participants