cascades are not beautiful (Bug #4153)


Added by Sheng Liu about 10 years ago. Updated about 10 years ago.


Status:Done Start date:2015-01-27
Priority:Normal Due date:
Assignee:Steven Puttemans % Done:

60%

Category:-
Target version:3.0-beta
Affected version:branch 'master' (3.0-dev) Operating System:Windows
Difficulty:Medium HW Platform:x64
Pull request:

Description

I specify path to XML with trained cascade. For example:
face_cascade_name="D:/opencv/data/haarcascades/haarcascade_frontalface_alt.xml"
face_cascade.load(face_cascade_name)

But XML file cannot be loaded.VS2013 and opencv3.0beta are installed in win8 64-bit.


Associated revisions

Revision 88691506
Added by Vadim Pisarevsky over 9 years ago

Merge pull request #4153 from stefan-cornelius:master

History

Updated by Alexander Alekhin about 10 years ago

  • Assignee deleted (Alexander Alekhin)

Updated by Sheng Liu about 10 years ago

  • Assignee set to Alexander Shishkov

Updated by Steven Puttemans about 10 years ago

Just applied the following code to a fresh 3.0 master branch build:

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/objdetect.hpp>

using namespace cv;
using namespace std;

int main()
{
    string cascade_name = "/home/spu/Documents/github/opencv3.0/data/haarcascades/haarcascade_frontalface_alt.xml";
    CascadeClassifier detector (cascade_name);

    Mat image = imread("/home/spu/Pictures/StevenPuttemansFoto.jpg");
    Mat image_gray;
    cvtColor(image, image_gray, CV_BGR2GRAY);
    equalizeHist(image_gray, image_gray);

    vector<Rect> objects;
    detector.detectMultiScale(image_gray, objects, 1.1, 3);

    for(size_t i = 0; i < objects.size(); i++ ){
        rectangle(image, objects[i], Scalar(255,0,0));
    }

    imshow("result", image); moveWindow("result", 50, 50);
    waitKey(0);
}

Resulted perfectly fine into the following result

So I am closing this down. Please motivate why or add more information on your configuration if you decide to reopen.

  • Status changed from New to Cancelled
  • Assignee deleted (Alexander Shishkov)

Updated by Steven Puttemans about 10 years ago

Oops I was to enthousiast there ... seems that the haarcascade actually generates and error! Will dig into this!

OpenCV Error: Assertion failed (!empty()) in detectMultiScale, file /home/spu/Documents/github/opencv3.0/modules/objdetect/src/cascadedetect.cpp, line 1582
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/spu/Documents/github/opencv3.0/modules/objdetect/src/cascadedetect.cpp:1582: error: (-215) !empty() in function detectMultiScale
  • Status changed from Cancelled to Open

Updated by Steven Puttemans about 10 years ago

Recancelling it! I had a simply typo in my haar cascade location. Just tested every single face model out there, and it still works!
Will see if I can update the code above!

  • Status changed from Open to Cancelled

Updated by Sheng Liu about 10 years ago

Thank you for your selfless help. The problem about cascadeclassifier has been borthering me a week. And the code you provided can work successfully on my machine.
I replaced the file "haarcascade_frontalface_alt. xml” in your code with other file in opencv, such as the files “haarcascade_eye_tree_eyeglasses. xml ”“haarcascade_frontalface alt2. xml ”,” haarcascade_frontalface_default.xml ”, ”haarcascade_righteye_2splits. xml”,
”haarcascade_smile. xml” .But the program cannot run after repalcing.Could you give me the reason?

  • % Done changed from 0 to 50
  • Target version set to 3.0-beta
  • Status changed from Cancelled to Open
  • Assignee set to Steven Puttemans

Updated by Steven Puttemans about 10 years ago

I am guessing that you are again incorrectly loading the model. Are you providing the correct path? What you could do is add the following code after your creating of your cascade classifier interface.

string cascade_name = "/home/spu/Documents/github/opencv3.0/data/haarcascades/haarcascade_frontalface_alt.xml";
CascadeClassifier detector (cascade_name);
if(detector.empty()){
   cerr << "The model could not be loaded, check your path!" << endl;
   break;
}

Mat image = imread("/home/spu/Pictures/StevenPuttemansFoto.jpg");

Updated by Sheng Liu about 10 years ago

I provide the correct path and some of the files can be load successfully,such as harrcascade_frontalface_alt.xml and harrcascade_eye.xml.

But some face detection files cannot work well,such as haarcascade_righteye_2splits.xml,haarcascade_eye_tree_eyeglasses.xml,haarcascade_lefteye_lefteye_2splits.xml and harrcascade_frontalface_alt_tree.xml.

  • % Done changed from 50 to 60

Updated by Sheng Liu about 10 years ago

Today I used another computer and found the code you provided cannot work.I'm sure I provide the correct path.

I guess windows8 and VS2013 don't support the cascadeclassifier in opencv3.0-beta. What should I do to solve the problem?

Updated by Steven Puttemans about 10 years ago

Sheng Liu wrote:

Today I used another computer and found the code you provided cannot work.I'm sure I provide the correct path.

I guess windows8 and VS2013 don't support the cascadeclassifier in opencv3.0-beta. What should I do to solve the problem?

Sorry but that just isn't possible. Are you sure that you configured your OpenCV installation correctly? ALSO, DO NOT USE BETA BUT USE THE 3.0 DEV BRANCH! It contains fixes, already pointed that out! Build OpenCV yourself on your system and see if it works.

As to the models, will check at my work pc tomorrow!

Updated by Sheng Liu about 10 years ago

Thank you!No matter whether the problem can be solved or not,I would like to send you a gift to express appreciation.Could you give me your mailing address by email?

Where can I find the link to download the 3.0 dev
branch?And what is the difference between 2.4.11 and 3.0.0?

Updated by Steven Puttemans about 10 years ago

The 3.0 dev branch is the current master branch of the github repository. This contains all the latest new stuff.
The 2.4 branch on github contains the most recent stable version.
Keep in mind that 3.0 has a little bit different interface.

As to testing the models. Ill keep you posted, going through them now!

Updated by Steven Puttemans about 10 years ago

So first test, seems that the face models work, as does the eye model and the eyeglasses.
Just bear in mind that it doesnt find faces sometimes but the models are loaded and detections performed.

I will look into the reason why the following models do not work:
  • haarcascade_righteye_2splits.xml
  • haarcascade_lefteye_lefteye_2splits.xml
  • haarcascade_upperbody.xml
  • haarcascade_smile.xml

Okay first of all, the loading of the models is just fine. It seems that the error occurs at detection time, so at the

detector.detectMultiScale(image_gray, objects, 1.1, 3);
code. Will see what I can do.

Updated by Steven Puttemans about 10 years ago

As to contacting me, you can send me a mail through my webpage under development: http://stevenputtemans.github.io/

Updated by Steven Puttemans about 10 years ago

Okay seems that there was a bug report some time ago and I was going to fix it but forgot it completely.
http://code.opencv.org/issues/3637#note-2

I will make the fixes and ensure that the models work again.

Updated by Steven Puttemans about 10 years ago

You can read in the other topic that 2 PRs have been submitted to solve problems for fullbody, upperbody, lowerbody and smile haarcascade classifier models.
Will look into those special eyeleft and eyeright why they still don't work.

Updated by Steven Puttemans about 10 years ago

Just to illustrate, checked again, must be a spelling mistake for the left and right eye.
Just applied the latest 2.4 and master branch and both models work!
I am guessing an earlier of my fixes where I updated models in both branches did the trick.

For example with the lefteye:

Updated by Steven Puttemans about 10 years ago

  • Status changed from Open to Done

Updated by Sheng Liu about 10 years ago

Could you tell me your mailing address?I decide to send presents to you.My e-mail is .

Also available in: Atom PDF