@@ -67,6 +67,7 @@ def __init__(self, parent=None):
6767 self .last_display_fps = time .time ()
6868 self .cv2 = None
6969 self .pyzbar = None
70+ self .scan_animation_position = 0
7071 try :
7172 # check if loading works
7273 # it depend on zlib installed in the os
@@ -403,10 +404,30 @@ def _numpy_to_surface(self, numpy_image: np.ndarray) -> pygame.Surface:
403404 # Convert numpy image (RGB) to pygame surface
404405 return pygame .surfarray .make_surface (numpy_image .transpose ((1 , 0 , 2 )))
405406
406- def _on_draw_surface (self , surface , barcode : BarcodeData ):
407+ def _on_draw_surface (self , surface : pygame . Surface , barcode : BarcodeData ):
407408 x , y , w , h = barcode .rect
408409 pygame .draw .rect (surface , (0 , 255 , 0 ), (x , y , w , h ), 2 )
409410
411+ def _draw_scan_animation_frame (self , surface : pygame .Surface ):
412+ # Define the color of the line (green)
413+ color = (0 , 255 , 0 ) # RGB for green
414+ self .scan_animation_position -= int (surface .get_height () / 64 )
415+
416+ # Define the thickness of the line
417+ thickness = 5
418+
419+ # the camera image has inverted x/y axis, so height and width are also flipped
420+ current_position = self .scan_animation_position % surface .get_height ()
421+ if current_position < 0 :
422+ current_position += surface .get_height () if current_position != 0 else 0
423+
424+ start_point = (0 , current_position )
425+ end_point = (surface .get_width (), current_position )
426+
427+ # Draw the line on the Pygame surface
428+ pygame .draw .line (surface , color , start_point , end_point , thickness )
429+ self .scan_animation_position = current_position
430+
410431 @staticmethod
411432 def crop (
412433 image_surface : pygame .Surface , left : float , right : float , top : float , bottom : float
@@ -574,8 +595,11 @@ def transform_and_detect(values: Tuple[int, int] | None) -> List[BarcodeData]:
574595
575596 if selected_barcode :
576597 self ._on_draw_surface (surface , selected_barcode )
598+ else :
599+ self ._draw_scan_animation_frame (surface )
577600
578601 surface = pygame .transform .flip (surface , False , True )
602+
579603 self .showSurface (surface , scale_to = (640 , 480 ))
580604
581605 if selected_barcode :
0 commit comments