Repository navigation
fix: degrade gracefully when OpenCV is present but unusable - #2
Open
hiroki-abe-58 wants to merge 1 commit into
Open
hiroki-abe-58 wants to merge 1 commit into
hiroki-abe-58 wants to merge 1 commit into
Conversation
detect_faces only caught ImportError. An importable OpenCV without CascadeClassifier (e.g. OpenCV 5.x), without cv2.data or cascade files, or one that fails at run time raised into pipeline.act() and turned a deterministic lattice/granule run into outcome "failed". Face protection is optional, so the OpenCV calls now run in a helper and any failure there degrades to no boxes: - OpenCV not installed: "cv2_unavailable" (unchanged) - present but unusable (failed import, missing API, no cascade loaded, runtime error): "cv2_error:<exception type>" Previously "no cascade could be loaded" was reported as haar_cascade_no_face. Box merging and the working OpenCV path are unchanged. Regression tests use small fake cv2 modules for each broken case and check that a lattice run still finishes with notch, verify and finish. Related to miyang-ai#1 (reported by greatweir-star). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Related to #1. Thanks to @greatweir-star for the detailed report and reproduction.
detect_facesonly caughtImportError. An OpenCV that imports but cannot be used raised intopipeline.act()and ended an otherwise deterministic lattice/granule run withoutcome: "failed". Examples are OpenCV 5.x without a top-levelCascadeClassifier, a build withoutcv2.dataor cascade files, or acv2.errorat run time.This PR keeps face protection best-effort and keeps the degraded state diagnosable:
[],cv2_unavailablecv2(e.g. DLL / ABI error)[],cv2_unavailable[],cv2_error:ImportErrorCascadeClassifier/ nocv2.dataAttributeError, runfailed[],cv2_error:AttributeError[],haar_cascade_no_face[],cv2_error:FileNotFoundErrordetectMultiScale, ...)failed[],cv2_error:<type>(cv2_error:errorforcv2.error)haar_cascade/haar_cascade_no_faceImplementation notes:
_haar_cascade_boxes().detect_faces()catchesException(notBaseException) only around thecv2import and that helper. Box merging stays outside thetry.CascadeClassifier: any failure in the OpenCV part degrades.pipeline.py, thresholds or signal-processing behaviour.Tests
tests/test_face_detection.pycovers:cv2modules (viamonkeypatch);cv2package whose import raises;pipeline.runwith a brokencv2, which must still finish withdiagnose → notch → verify → finishand verify passed.Verification
Local only: Windows 11, Python 3.12.13, numpy 2.5.3.
main(865a148): 6 failed, 2 passed. The 2 that pass are the unchanged paths.pytest23 passed.opencv-python-headless4.14.0.94 (.[face]):pytest23 passed.ruff check .is clean.detect_facesreturns identical boxes and status on unmodifiedmainand on this branch for 7 local test images (one with a detected box).🤖 Generated with Claude Code