Advertisement
Guest User

Untitled

a guest
Oct 20th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. async def scan_qr(area: int = 300, color: int = 196, side: int = 240, lang: str = "en", debug: bool = False) -> None:
  2.     """Main function that creates a screen with the capture, monitors the web-cam's stream, searches for a QR-code in a squared area and passes
  3.    the decoded QR-code to the notify module.
  4.  
  5.    Args:
  6.        [optional] area (int): Minimal area of a detected object to be consider a QR-code.
  7.        [optional] color (int): Minimal hue of gray of a detected object to be consider a QR-code (since QR-codes have white borders).
  8.        [optional] side (int): Length of the side of a square to be drawn in the center of the screen and monitor the inside area for QR-codes.
  9.        [optional] lang (str): Language of a text to be written above the square.
  10.        [optional] debug (bool): Crops and outputs an image containing inside the square at potential detection.
  11.    """
  12.  
  13.     kernel = np.ones((2, 2), np.uint8)
  14.     square = create_square(cap.read()[1], side=side)
  15.  
  16.     while cap.isOpened():
  17.         ret, frame = cap.read()
  18.         key = cv2.waitKey(1)
  19.  
  20.         if not ret or square is None or ((key & 0xFF) in {27, ord("Q"), ord("q")}):
  21.             exit(1)
  22.  
  23.         image = draw_bounds(frame, square, lang=lang)
  24.         detected, cropped = detect_inside_square(frame, square, kernel, area_min=area, color_lower=color, debug=debug)
  25.  
  26.         if detected:
  27.             address = detect_qr(cropped)
  28.  
  29.             if address:
  30.                 await notify.start(address)
  31.                
  32.         cv2.imshow("Live Capture", image)
  33.         time.sleep(0.1)
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement