CultriX commited on
Commit
24c48fb
·
verified ·
1 Parent(s): 368d01c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -25,8 +25,17 @@ def generate_qr(data):
25
 
26
  # Function to read a QR code using OpenCV
27
  def read_qr(img):
 
 
 
 
 
 
 
 
28
  detector = cv2.QRCodeDetector()
29
  data, _, _ = detector.detectAndDecode(img)
 
30
  return data if data else "No QR code found."
31
 
32
  # Custom CSS styling as HTML for dark mode
 
25
 
26
  # Function to read a QR code using OpenCV
27
  def read_qr(img):
28
+ # Convert PIL image to a NumPy array
29
+ img = np.array(img)
30
+
31
+ # Convert RGB to BGR format as OpenCV expects BGR
32
+ if img.ndim == 3:
33
+ img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
34
+
35
+ # Initialize OpenCV QR code detector
36
  detector = cv2.QRCodeDetector()
37
  data, _, _ = detector.detectAndDecode(img)
38
+
39
  return data if data else "No QR code found."
40
 
41
  # Custom CSS styling as HTML for dark mode