What does the Java – cvhaardetectobjects () method do?
Some experts can explain whether I can use the cvhaardetectobjects () method to detect the box and obtain the width and height? I found a code that uses this method for face detection, but I need to know whether it can be used for rectangle detection
String src="src/squiredetection/MY.JPG"; IplImage grabbedImage = cvLoadImage(src); IplImage grayImage = IplImage.create(grabbedImage.width(),grabbedImage.height(),IPL_DEPTH_8U,1); cvCvtColor(grabbedImage,grayImage,CV_BGR2GRAY); CvSeq faces = cvHaarDetectObjects(grayImage,cascade,storage,1.1,3,0);//* for (int i = 0; i < faces.total(); i++) { CvRect r = new CvRect(cvGetSeqElem(faces,i)); cvRectangle(grabbedImage,cvPoint(r.x(),r.y()),cvPoint(r.x()+r.width(),r.y()+r.height()),CvScalar.RED,1,CV_AA,0); /* hatPoints[0].x = r.x-r.width/10; hatPoints[0].y = r.y-r.height/10; hatPoints[1].x = r.x+r.width*11/10; hatPoints[1].y = r.y-r.height/10; hatPoints[2].x = r.x+r.width/2; hatPoints[2].y = r.y-r.height/2;*/ // cvFillConvexPoly(grabbedImage,hatPoints,hatPoints.length,CvScalar.GREEN,0); }
When I use the above method, it throws the following exception
OpenCV Error: Bad argument (Invalid classifier cascade) in unkNown function,file C:\slave\WinInstallerMegaPack\src\opencv\modules\objdetect\src\haar.cpp,line 1036 Exception in thread "main" java.lang.RuntimeException: C:\slave\WinInstallerMegaPack\src\opencv\modules\objdetect\src\haar.cpp:1036: error: (-5) Invalid classifier cascade at com.googlecode.javacv.cpp.opencv_objdetect.cvHaarDetectObjects(Native Method) at com.googlecode.javacv.cpp.opencv_objdetect.cvHaarDetectObjects(opencv_objdetect.java:243) at squiredetection.Test2.main(Test2.java:52 I have put * on this line)
Please kindly provide a simple code example for this
Solution
Cvhaardetectobjects () is not only used to detect the object or shape of the face, but also depends on the haarccascade classifier
If you pass face haarccascade XML, then it will return an array of faces, or you can also use haarccascade XML files such as eyes and nose You can also use OpenCV_ traincascade. Exe creates its own positive and negative samples to make custom haarcascade XML
CvSeq faces = cvHaarDetectObjects(grayImage,classifier,CV_HAAR_DO_CANNY_PRUNING); for (int i = 0; i < faces.total(); i++) { // its ok }
Details opencv doc
For rectangle detection:
See chessboard detection sample in opencv
An invalid classifier cascade in an unknown function error means that the classifier you passed is malformed or missing something Check whether the classifier XML file is valid