Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 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)):
|