Hayk Arutyunyan commited on
Commit ·
60b90b9
1
Parent(s): 1dde15b
Fix ocr code
Browse files- src/ocr_utils_demo.py +13 -4
src/ocr_utils_demo.py
CHANGED
|
@@ -69,15 +69,24 @@ def ocr_sensors(rois: list[np.ndarray]):
|
|
| 69 |
results.append({"text": "?", "score": 0.0})
|
| 70 |
continue
|
| 71 |
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
results.append({"text": "?", "score": 0.0})
|
| 74 |
continue
|
| 75 |
|
| 76 |
-
text, score = ocr_res[0][
|
| 77 |
|
| 78 |
results.append({
|
| 79 |
-
"text": text,
|
| 80 |
-
"score": float(score)
|
| 81 |
})
|
| 82 |
|
| 83 |
return results
|
|
|
|
| 69 |
results.append({"text": "?", "score": 0.0})
|
| 70 |
continue
|
| 71 |
|
| 72 |
+
# -------- Безопасная распаковка --------
|
| 73 |
+
if (
|
| 74 |
+
not ocr_res
|
| 75 |
+
or not isinstance(ocr_res, list)
|
| 76 |
+
or not ocr_res[0]
|
| 77 |
+
or not isinstance(ocr_res[0], list)
|
| 78 |
+
or not ocr_res[0][0]
|
| 79 |
+
or not isinstance(ocr_res[0][0], tuple)
|
| 80 |
+
or len(ocr_res[0][0]) < 2
|
| 81 |
+
):
|
| 82 |
results.append({"text": "?", "score": 0.0})
|
| 83 |
continue
|
| 84 |
|
| 85 |
+
text, score = ocr_res[0][0]
|
| 86 |
|
| 87 |
results.append({
|
| 88 |
+
"text": text if text else "?",
|
| 89 |
+
"score": float(score) if score else 0.0
|
| 90 |
})
|
| 91 |
|
| 92 |
return results
|