SuriRaja commited on
Commit
dc24cfa
·
verified ·
1 Parent(s): 9b0126c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -46,20 +46,20 @@ def detect_qr_opencv(image_np: np.ndarray) -> List[Dict[str, Any]]:
46
  Use OpenCV's QRCodeDetector to find and decode QR codes.
47
  Returns list of dicts: {bbox: [x1,y1,x2,y2], data: str, points: np.ndarray}
48
  """
 
49
  det = cv2.QRCodeDetector()
50
- data, points, _ = det.detectAndDecodeMulti(image_np)
51
- results = []
52
- if points is None:
53
- # Try single QR fallback
54
- data_single, points_single, _ = det.detectAndDecode(image_np)
55
- if points_single is not None and data_single:
56
- pts = np.array(points_single, dtype=np.float32).reshape(-1, 2)
57
- x1, y1 = np.min(pts[:,0]), np.min(pts[:,1])
58
- x2, y2 = np.max(pts[:,0]), np.max(pts[:,1])
59
- results.append({"bbox": [float(x1), float(y1), float(x2), float(y2)],
60
- "data": data_single,
61
- "points": pts.tolist()})
62
- return results
63
 
64
  # points shape: (N,4,2), data is list/tuple of strings (may be '' for undecodeable)
65
  if isinstance(data, (list, tuple)):
 
46
  Use OpenCV's QRCodeDetector to find and decode QR codes.
47
  Returns list of dicts: {bbox: [x1,y1,x2,y2], data: str, points: np.ndarray}
48
  """
49
+ def detect_qr_opencv(image_np):
50
  det = cv2.QRCodeDetector()
51
+
52
+ try:
53
+ # For OpenCV >= 4.5.3
54
+ retval, decoded_info, points, _ = det.detectAndDecodeMulti(image_np)
55
+ if retval:
56
+ return decoded_info, points
57
+ else:
58
+ return [], []
59
+ except:
60
+ # Fallback to single QR detection
61
+ data, points, _ = det.detectAndDecode(image_np)
62
+ return [data] if data else [], points
 
63
 
64
  # points shape: (N,4,2), data is list/tuple of strings (may be '' for undecodeable)
65
  if isinstance(data, (list, tuple)):