The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.
JavaScript
Answer an OpenCV assertion the way auto-stitch answers a refusal (#62)
OsintMeThat99f423abf63a
diff --git a/src/azimut/engine/stitch.py b/src/azimut/engine/stitch.pyindex 1402fd9..cf14329 100644--- a/src/azimut/engine/stitch.py+++ b/src/azimut/engine/stitch.py@@ -523,7 +523,16 @@ def _solve_cameras(cv2, feats: list[Any], pairwise: list[Any]) -> list[Any]:"""import numpy as np- ok, cameras = cv2.detail_HomographyBasedEstimator().apply(feats, pairwise, None)+ # Both solvers answer a scene they cannot resolve two ways: `False`, or an+ # assertion from inside OpenCV. Pieces that overlap just enough to be matched+ # but not enough to be solved take the second road — the ray adjuster asserts+ # on an empty error term rather than reporting failure — and an uncaught+ # `cv2.error` leaves the route with a 500 and a traceback where the analyst+ # should be reading that these pictures do not solve. One outcome, one answer.+ try:+ ok, cameras = cv2.detail_HomographyBasedEstimator().apply(feats, pairwise, None)+ except cv2.error:+ ok = Falseif not ok:raise RuntimeError("auto-stitch could not estimate the camera rotations")for cam in cameras:@@ -532,7 +541,10 @@ def _solve_cameras(cv2, feats: list[Any], pairwise: list[Any]) -> list[Any]:adjuster = cv2.detail_BundleAdjusterRay()adjuster.setConfThresh(STITCH_CONF)adjuster.setRefinementMask(np.ones((3, 3), np.uint8))- ok, cameras = adjuster.apply(feats, pairwise, cameras)+ try:+ ok, cameras = adjuster.apply(feats, pairwise, cameras)+ except cv2.error:+ ok = Falseif not ok:raise RuntimeError("auto-stitch could not refine the camera rotations")diff --git a/tests/test_stitch.py b/tests/test_stitch.pyindex 550d69a..756c7a9 100644--- a/tests/test_stitch.py+++ b/tests/test_stitch.py@@ -258,6 +258,68 @@ def test_rotation_layout_rejects_an_unknown_warp():stitch.solve_rotation_layout(_pan([0, 20]), width=800, height=600, warp="planar")+class _FakeCv2:+ """Just enough of cv2 for `_solve_cameras`, with either solver set to blow up.++ OpenCV reports a scene it cannot resolve two ways — `False`, or an assertion+ thrown from inside the solver — and only the first was ever handled. Driven+ through a stand-in rather than through real pictures, because the input that+ makes the real adjuster assert is a property of the OpenCV build, not+ something a fixture can promise across versions.+ """++ error = type("error", (Exception,), {})++ def __init__(self, raise_in: str):+ self._raise_in = raise_in++ class _Camera:+ def __init__(self):+ import numpy as np++ self.R = np.eye(3, dtype="float64")+ self.focal = 500.0++ def _apply(self, which):+ if self._raise_in == which:+ raise self.error("(-215:Assertion failed) !err.empty() in function 'update'")+ return True, [self._Camera(), self._Camera()]++ def detail_HomographyBasedEstimator(self):+ outer = self++ class _Estimator:+ def apply(self, feats, pairwise, _):+ return outer._apply("estimator")++ return _Estimator()++ def detail_BundleAdjusterRay(self):+ outer = self++ class _Adjuster:+ def setConfThresh(self, value): ...++ def setRefinementMask(self, mask): ...++ def apply(self, feats, pairwise, cameras):+ return outer._apply("adjuster")++ return _Adjuster()+++ ("raise_in", "says"),+ [("estimator", "estimate the camera rotations"), ("adjuster", "refine the camera rotations")],+)+def test_solve_cameras_answers_an_opencv_assertion_like_a_refusal(raise_in, says):+ # Pieces that match just enough to be paired but not enough to be solved reach+ # the ray adjuster and make it assert. Uncaught, that is a 500 and a traceback+ # where the analyst should be reading that these pictures do not solve.+ with pytest.raises(RuntimeError, match=says):+ stitch._solve_cameras(_FakeCv2(raise_in), feats=[], pairwise=[])++# --- fixed overlays --------------------------------------------------------