# PSA: CascadeClassifier with a missing file does not raise, it fails later in detectMultiScale

**URL:** <https://forum.opencv.org/t/psa-cascadeclassifier-with-a-missing-file-does-not-raise-it-fails-later-in-detectmultiscale/24719>\
**Category:** Uncategorized\
**Created:** [September 21, 2026, 8:21pm UTC](https://forum.opencv.org/t/psa-cascadeclassifier-with-a-missing-file-does-not-raise-it-fails-later-in-detectmultiscale/24719 "2026-09-21T20:21:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ColinGPT9](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@ColinGPT9](https://forum.opencv.org/u/ColinGPT9)\
**Post date:** [September 21, 2026, 8:21pm UTC](https://forum.opencv.org/t/psa-cascadeclassifier-with-a-missing-file-does-not-raise-it-fails-later-in-detectmultiscale/24719/1 "2026-09-21T20:21:15Z")

</div>

Posting this because it cost me a release and the failure mode points nowhere  
near the cause.

cv2.CascadeClassifier given a path that does not exist does NOT raise. You get  
back an empty classifier, everything looks fine, and the error only appears  
later, inside detectMultiScale:

```auto
(-215:Assertion failed) !empty() in function 'detectMultiScale'

```

Worse, it is invisible in development. It worked perfectly from a checkout and  
broke every affected render in the installed build, because the frozen app  
ships cv2 without its data directory, so the cascade XML simply is not there.  
Same code, same version, different packaging.

Two things that fixed it:

1. Resolve the cascade path explicitly rather than relying on cv2’s data  
directory being present, and treat a missing file as “no classifier” rather  
than handing an empty one downstream.

2. Build the cascades per thread. detectMultiScale is not thread-safe on a  
shared instance, which is a separate trap if you are running detection  
across parallel workers.

For context on where this bit me: I use YOLOv8 to find people, OpenCV Haar  
cascades to find the face inside each person box, and TalkNet-ASD to work out  
which of those faces is actually the one talking, so a 16:9 stream can be  
cropped to 9:16 following the speaker rather than the biggest face. All local.  
The cascade step is the fallback path, which is exactly why it went unnoticed  
for a while.

The clip-selection side is a documented plug-in point if the pipeline is  
useful to anyone:

> <https://github.com/ColinGPT9/clips-studio/blob/main/docs/EXTENDING.md#bring-your-own-model>

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [September 22, 2026, 7:14am UTC](https://forum.opencv.org/t/psa-cascadeclassifier-with-a-missing-file-does-not-raise-it-fails-later-in-detectmultiscale/24719/2 "2026-09-22T07:14:34Z")

</div>

after loading, before detecting, check explicitly:

```python
assert not detector.empty()

```

```cpp
assert(!detector.empty());

```
