# Cascade Classifier Training - Application: opencv\_traincascade

**URL:** <https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047>\
**Category:** Uncategorized\
**Tags:** opencv\_traincascade, build\
**Created:** [March 9, 2021, 1:24pm UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047 "2021-03-09T13:24:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![H\_D](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@H\_D](https://forum.opencv.org/u/H_D)\
**Post date:** [March 9, 2021, 1:24pm UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/1 "2021-03-09T13:24:48Z")

</div>

For _Cascade Classifier Training_ , the _opencv\_traincascade_ application as mentioned here:

[http://docs.opencv.org/master/dc/d88/tutorial\_traincascade.html](http://docs.opencv.org/master/dc/d88/tutorial_traincascade.html)

The source code does not compile as some of the files with the _old\_ml_ prefix in the source code make reference to a _CvFileStorage_ data structure. This seems not to be present in version 4.x of OpenCV (Documentation has it listed in version 3.x).

How can I build this application ? (I would like to for version 4.x and 32-bit & 64-bit, dynamic linked & static linked)

---

<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:** [March 9, 2021, 2:20pm UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/2 "2021-03-09T14:20:52Z")

</div>

indeed, the train cascade tools can no longer be built with 4.x

> [@H\_D](#):
>
> How can I build this application ?

as of now, you have to checkout the 3.4 branch (which still has the missing c-api parts) by either

```
// if you got it via git, just change the branch
cd opencv
git checkout 3.4 

// else download anew
git clone -b 3.4 https://github.com/opencv/opencv.git

```

anyway, you’ll have to remove all your previous cmake artefacts, and start all over.

---

<div class="post-metadata">

**Author:** ![H\_D](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@H\_D](https://forum.opencv.org/u/H_D)\
**Post date:** [March 9, 2021, 4:24pm UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/3 "2021-03-09T16:24:00Z")

</div>

So I have to use version 3.4 to build the tool ?.

Also, why was the tool not updated for 4.x ?, was there some limiting factor ?

---

<div class="post-metadata">

**Author:** ![H\_D](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@H\_D](https://forum.opencv.org/u/H_D)\
**Post date:** [March 9, 2021, 11:32pm UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/4 "2021-03-09T23:32:20Z")

</div>

@berek

I tried building with 3.4. But I get huge amount of compiler errors.

Are you sure it **actually** _will_ compile with 3.4 ?.

Can you give _ **fool-proof** _ _step by step_ instructions, from **scratch**? (include _a_ll steps such as _download,extract,configuration,setup,Visual Studio Project configuration, etc…_), for _every_ file. - For _Static_ and _Dynamic (Shared)_, _32-Bit_ and _64-Bit_, using _Visual Studio 2019 ( Windows 7 SP1)_

---

<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:** [March 10, 2021, 10:43am UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/5 "2021-03-10T10:43:06Z")

</div>

> [@H\_D](#):
>
> Are you sure it **actually** _will_ compile with 3.4 ?.

[well, it should](https://pullrequest.opencv.org/buildbot/builders/3_4-contrib-win64-vc14/builds/999)

> [@H\_D](#):
>
> Can you give _ **fool-proof** _ _step by step_ instructions

sorry, i can’t, not using VS (mayne someone else ?)

> [@H\_D](#):
>
> For _Static_ and _Dynamic_

this is controlled by a cmake flag, irresp. of the compiler used.

in cmake, set `BUILD_SHARED_LIBS=OFF` for building and linking against static libs

apart from that, please clarify, what you want to detect later (is this even the correct tool ?)  
have you considered different means to do so, like HogDetector or some (pre or re) - trained network ?

---

<div class="post-metadata">

**Author:** ![H\_D](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@H\_D](https://forum.opencv.org/u/H_D)\
**Post date:** [March 10, 2021, 3:26pm UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/6 "2021-03-10T15:26:09Z")

</div>

Yes correct tool, been referred to it by the tutorials.

When compiling I get Build error output:

`1>C:\OpenCV_3.4.13\traincascade\old_ml_precomp.hpp(49,10): fatal error C1083: Cannot open include file: 'opencv2/core/private.hpp': No such file or directory`

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [March 10, 2021, 4:22pm UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/7 "2021-03-10T16:22:19Z")

</div>

Is traincascade program really needed for your application? to update (opencv 4.5.2) it you will need not only one day

---

<div class="post-metadata">

**Author:** ![H\_D](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@H\_D](https://forum.opencv.org/u/H_D)\
**Post date:** [March 10, 2021, 5:13pm UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/8 "2021-03-10T17:13:32Z")

</div>

> [@laurent.berger](#):
>
> n

I do not understand the 2nd half of the questions, after the questions mark, but I answer as best as I can:

Yes it is needed, for training, cannot without it. I will be using it many times (not just once).

I got the source supplied with 3.4 to build with 3.4. But cannot get the source supplied with 4.6 to build with 3.4 (content is different)  
?

---

<div class="post-metadata">

**Author:** ![beslytk](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@beslytk](https://forum.opencv.org/u/beslytk)\
**Post date:** [August 10, 2021, 9:48am UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/9 "2021-08-10T09:48:20Z")

</div>

Hi, I’m at the same juncture. Is there a workaround to using the train cascade tools with opencv 4.x versions?

---

<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:** [August 10, 2021, 11:27am UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/10 "2021-08-10T11:27:44Z")

</div>

> [@beslytk](#):
>
> using the train cascade tools with opencv 4.x versions?

no there isnt.  
check out the 3.4 branch, and build that together with the apps

---

<div class="post-metadata">

**Author:** ![Matias\_Chaied](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/matias_chaied/32/7251_2.png) [@Matias\_Chaied](https://forum.opencv.org/u/Matias_Chaied)\
**Post date:** [February 27, 2023, 1:32pm UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/11 "2023-02-27T13:32:14Z")

</div>

Hello, I know this is old but I´m having the same trouble, also I download the 3.4 version of opencv and opencv\_contrib and configured it with cmake but then when I load the solution with visual studio 2019 I get a lot of compiler errors so I guess the only thing that we can do is to fix all those hundreds and unplacent errors… Maybe now with ChatGPT we can fix those errors? don´t know for sure

---

<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:** [February 27, 2023, 1:51pm UTC](https://forum.opencv.org/t/cascade-classifier-training-application-opencv-traincascade/2047/12 "2023-02-27T13:51:57Z")

</div>

simply, don’t insist on using EOL code.

please, ask a new question, describe **exactly** , what you are trying to detect, and where (in 95% of all cases, cascades are the wrong tool for it, anyway !!!)
