# I have problem with detectMultiScale method in my project

**URL:** <https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496>\
**Category:** Android/Java\
**Created:** [June 13, 2023, 11:01am UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496 "2023-06-13T11:01:00Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael061](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Michael061](https://forum.opencv.org/u/Michael061)\
**Post date:** [June 13, 2023, 11:01am UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/1 "2023-06-13T11:01:00Z")

</div>

Hi everyone. Please if someone have any information about how to find solve for this Exception, you will he;lp me very much.

`E/cv::error(): OpenCV(3.4.15) Error: Assertion failed (!empty()) в void cv::CascadeClassifier::detectMultiScale(cv::InputArray, std::vector<cv::Rect_ < int> >&, double, int, int, cv::Size, cv::Size), file/build/3_4_pack-android/opencv/modules/objdetect/src/cascadedetect.cpp, line 1729`

`E/org.opencv . objdetect: objdetect::detectMultiScale_15() caught cv::Exception: OpenCV(3.4.15) /build/3_4_pack-android/opencv/modules/objdetect/src/cascadedetect.cpp:1729: error: (-215: Assertion failed ) !empty() in function 'void cv::CascadeClassifier::detectMultiScale(cv::InputArray, std::vector<cv::Rect_<int> >&, double, int, int, cv::Size, cv: : Size)'`

`E/AndroidRuntime: FATAL EXCEPTION: Process Thread-2: com.example.eyecontrolmediaplayer, PID: 28922 CvException [org.opencv.core.CvException: cv:: Exception: OpenCV(3.4.15) /build/3_4_pack-android/opencv/modules/objdetect/src/cascadedetect.cpp:1729: error: (-215: Assertion failed) !empty() in function'void cv:: CascadeClassifier::detectMultiScale(cv: :InputArray, std::vector<cv::Rect_<int> >&, double, int, int, cv::Size, cv::Size)'`

This error appear when project steps into detectMultiScale method in my project. I’m using the haarcascade\_eye.xml file in my CascadeClassifier class. I have this xml file in assets folder in to project folder, but I don’t know why I have this error?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [June 13, 2023, 11:11am UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/2 "2023-06-13T11:11:34Z")

</div>

> [@Michael061](#):
>
> I’m using the haarcascade\_eye.xml file

problem is, it was not found / loaded (so the cascade is ‘empty()’)

> [@Michael061](#):
>
> I have this xml file in assets folder in to project folder,

opencv cannot read directly from your assets folder  
(which is zipped inside your apk, right ?)

before you can use it, you need to copy it to /tmp , /sdcard or similar, then read from there.

please have a look at [how it is done in the sample app](https://github.com/opencv/opencv/blob/e60a7c0d490b5bd94524680deb74177d7bfb9ae4/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java#L72-L101)

---

<div class="post-metadata">

**Author:** ![Michael061](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Michael061](https://forum.opencv.org/u/Michael061)\
**Post date:** [June 13, 2023, 11:21am UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/3 "2023-06-13T11:21:28Z")

</div>

> [@berak](#):
>
> opencv cannot read directly from your assets folder  
> (which is zipped inside your apk, right ?)

My haarcascade file is not zipped, I put it right in My project folder like this `C:\Users\user\MyProject\app\main\src\assets\haarcascade_eye.xml` file, and use this path in my code.

---

<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:** [June 13, 2023, 11:33am UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/4 "2023-06-13T11:33:56Z")

</div>

that path may exist on your computer, but not on your android device.

does that make sense to you?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [June 13, 2023, 11:36am UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/5 "2023-06-13T11:36:32Z")

</div>

again, when building the apk, that asset folder will end up, zipped, inside of the apk.  
c-code, like fopen() cannot reach it there (different to java !)

similar problem for nn models, pretrained tracker files, _anything_ you’d just load ‘from disk’ on a pc.

when you compile / build your program, your phone is not present, so no hd / sdcard to put it, that’s why such files end up (temporary) in your ‘assets’ folder in your project

---

<div class="post-metadata">

**Author:** ![Michael061](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Michael061](https://forum.opencv.org/u/Michael061)\
**Post date:** [June 13, 2023, 11:59am UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/6 "2023-06-13T11:59:35Z")

</div>

> [@crackwitz](#):
>
> does that make sense to you?

Yes, this is sense to me very much. I’m real didn’t know how I can use the cascade file in my android project on android device. Have you some samples how it’s sovle by someone else, or maybe you have some links when I can find the solution of this problem?

---

<div class="post-metadata">

**Author:** ![Michael061](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Michael061](https://forum.opencv.org/u/Michael061)\
**Post date:** [June 13, 2023, 12:04pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/7 "2023-06-13T12:04:12Z")

</div>

So what I need to do? I see the sample in the link which you are send me, but I not sure that I can use this in my android project. I copy/paste this code, but there is many moments wich I can uderstand, like InputStream is = getResources().openRawResource(R.raw.lbpcascade\_frontalface). I’m real don’t know what are raw is this…

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [June 13, 2023, 12:09pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/8 "2023-06-13T12:09:15Z")

</div>

in the sample, the file is put under /res/raw (not into assets)

> **[opencv/samples/android/face-detection/res at 4.x · opencv/opencv](https://github.com/opencv/opencv/tree/4.x/samples/android/face-detection/res)**
>
> 4.x/samples/android/face-detection/res

---

<div class="post-metadata">

**Author:** ![Michael061](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Michael061](https://forum.opencv.org/u/Michael061)\
**Post date:** [June 13, 2023, 12:13pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/9 "2023-06-13T12:13:54Z")

</div>

> [@berak](#):
>
> in the sample, the file is put under /res/raw (not into assets)

I don’t have the /res/raw folder in my project, the studio ask me to create the raw resouse file haarcascade\_eye.xml but there no raw folder, I can create that file in some others folders like values, xml, drawable and etc. May I create the raw folder by my self like New-folder-raw and then put this raw folder in my res folder?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [June 13, 2023, 2:34pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/10 "2023-06-13T14:34:57Z")

</div>

IF you have a res folder already – sure, go try !

---

<div class="post-metadata">

**Author:** ![Michael061](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Michael061](https://forum.opencv.org/u/Michael061)\
**Post date:** [June 13, 2023, 2:47pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/11 "2023-06-13T14:47:59Z")

</div>

I’ll tryed, but it’s doesn’t work. I really dont know what to do.

---

<div class="post-metadata">

**Author:** ![Michael061](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Michael061](https://forum.opencv.org/u/Michael061)\
**Post date:** [June 13, 2023, 2:50pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/12 "2023-06-13T14:50:29Z")

</div>

```auto
 public EyeDetectionClass(){
        String path = "MyProject\\app\\src\\main\\res\\raw\\haarcascade_eye.xml";
        eyeCascade = new CascadeClassifier();
        eyeCascade.load(path);
    } 

```

This is my block of code, of constructor for this class, where I try load cascade file.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [June 13, 2023, 2:57pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/13 "2023-06-13T14:57:55Z")

</div>

you don’t listen, do you ?

> [@berak](#):
>
> before you can use it, you need to copy it to /tmp , /sdcard or similar, then read from there.
> 
> please have a look at [how it is done in the sample app](https://github.com/opencv/opencv/blob/e60a7c0d490b5bd94524680deb74177d7bfb9ae4/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java#L72-L101)

---

<div class="post-metadata">

**Author:** ![Michael061](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Michael061](https://forum.opencv.org/u/Michael061)\
**Post date:** [June 13, 2023, 3:39pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/14 "2023-06-13T15:39:41Z")

</div>

> [@berak](#):
>
> прежде чем вы сможете его использовать, вам нужно скопировать его в /tmp , /sdcard или аналогичный, а затем прочитать оттуда.
> 
> пожалуйста, посмотрите, [как это делается в примере приложения](https://github.com/opencv/opencv/blob/e60a7c0d490b5bd94524680deb74177d7bfb9ae4/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java#L72-L101)

In this sample I don’t see how I can put this is the /tmp or /sdcard. How I can do this? I doing my project on computer, not on phone, so I have all files on computer, and I don’t know how I can put this file in tmp folder. If I need that my app will be installed on many devices, I can’t copy this file in the tmp folder in each device, how can I do this automaticly? What information I need take from this sample? This sample have in opencv java folder wich I download from [opencv.org](http://opencv.org), but I don’t know what I need to see in this code, what can help me find the soution.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [June 13, 2023, 4:41pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/15 "2023-06-13T16:41:22Z")

</div>

> [@Michael061](#):
>
> If I need that my app will be installed on many devices, I can’t copy this file in the tmp folder in each device, how can I do this automaticly?

that is exactly, what the sample code is doing, look again.

---

<div class="post-metadata">

**Author:** ![Michael061](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Michael061](https://forum.opencv.org/u/Michael061)\
**Post date:** [June 13, 2023, 5:41pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/16 "2023-06-13T17:41:11Z")

</div>

> [@berak](#):
>
> that is exactly, what the sample code is doing, look again.

There are 2 methods here that cannot be recognized: getResources(), getDir() what should I do with them? The studio says that I need to declare them in the class, I do it, but they both return null, what should I do in this case? I already tried this example code, I understand what it does, but these methods don’t work…

---

<div class="post-metadata">

**Author:** ![Michael061](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Michael061](https://forum.opencv.org/u/Michael061)\
**Post date:** [June 13, 2023, 5:44pm UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/17 "2023-06-13T17:44:16Z")

</div>

> [@berak](#):
>
> that is exactly, what the sample code is doing, look again.

I think that this sample don’t work for Android applications. I’m completely confused, I have no idea what to do.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [June 14, 2023, 4:58am UTC](https://forum.opencv.org/t/i-have-problem-with-detectmultiscale-method-in-my-project/13496/19 "2023-06-14T04:58:09Z")

</div>

[https://guides.codepath.com/android/Understanding-App-Resources](https://guides.codepath.com/android/Understanding-App-Resources)

apart from your current, android coding problems (where we can’t help, probably) –

i have no idea, what your app does in the end, but trying to find eyes using cascades _without_ a previous face detection (and restricting eye-search to that region) will be terribly inaccurate.

keep an eye on [FaceDetectorYN (OpenCV 4.7.0 Java documentation)](https://docs.opencv.org/4.x/javadoc/org/opencv/objdetect/FaceDetectorYN.html) , which returns face rects + 5 landmarks (eyes, nose, mouth)  
(however, same problem with android, it needs external pretrained models / resources, …)
