Ask Your Question
0

I can't detect full body in java

asked 2013-03-31 09:49:11 -0600

emre gravatar image

updated 2013-03-31 09:50:22 -0600

While I use haarcascade_upperbody.xml to detection in videocapture, I never get any error or problem but when I used haarcascade_fullbody.xml program couldn't detect anyone's body.. I am going to use finding human heigth...if you give some hints, solutions or advising another way for this problem, I will very pleased...thanks for reading

here is my code :

package main;

import javax.swing.JOptionPane;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;
import org.opencv.objdetect.CascadeClassifier;

public class ResimCek {

public void resimCek() throws InterruptedException{
    System.loadLibrary("opencv_java244");
    CascadeClassifier cascadeClassifier = new CascadeClassifier("haarcascade_fullbody.xml");
    VideoCapture cap = new VideoCapture(0);
    if(!cap.isOpened())
        JOptionPane.showMessageDialog(null, "Cam can not found", "Error", JOptionPane.ERROR_MESSAGE);

    Mat frame = new Mat();
    cap.retrieve(frame);
    Highgui.imwrite("cek.jpg", frame);
    cap.release();
    Mat resim = Highgui.imread("cek.jpg");
    MatOfRect rect = new MatOfRect();
    cascadeClassifier.detectMultiScale(resim, rect);
    Scalar renk = new Scalar(255, 0, 0);
    for(Rect dik : rect.toArray()){
        Core.rectangle(resim, new Point(dik.x, dik.y), new Point(dik.x+ dik.width, dik.y+dik.height), renk);
    }
    System.out.println(rect.height());
    Highgui.imwrite("dene.jpg", resim);
    }
}
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-03-31 09:56:54 -0600

Add more options to the detection function. Try the following, which basically allows you to draw all hits, even if no overlaps occur. If nothing happens, then please add an example picture. It can be that your dataset is not corresponding to the used training situations for the model itself.

cascadeClassifier.detectMultiScale(resim, rect);
--> CHANGE THIS LINE INTO
cascadeClassifier.detectMultiScale(resim, rect, 1.05, 0);
edit flag offensive delete link more

Comments

1

thanks this solution is working rigth (just I guess cascadeClassifier.detectMultiScale(resim, rect, 1.05, 0); should be cascadeClassifier.detectMultiScale(resim, rect, 1, 1.05); because double and int values are in different parametres)...

emre gravatar imageemre ( 2013-03-31 10:07:37 -0600 )edit

Weird the c++ docs say the following parameters should follow: name image, bounding box container, scale factor, minNeighbors. (http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=detectmultiscale#cv2.CascadeClassifier.detectMultiScale) this is first double then int. However wrapper of Java bindings uses name, bounding box, rejectlevels, levelweights, ... You should check good values for that, i have no experience with java opencv.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-31 10:25:30 -0600 )edit

Ow i am wrong, there is a correct binding for java also, add the following code

  void  detectMultiScale(Mat image, MatOfRect objects, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize)
StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-31 10:28:00 -0600 )edit
0

answered 2014-06-14 08:40:06 -0600

hello, I use opencv-2.4.9, in 2.4.9 edition,it likes this: detectMultiScale(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights) so, how should I set the parameters ? very grateful for your kind reply.

edit flag offensive delete link more

Comments

1

dear, please read the faq, remove this answer, and start your own question ...

berak gravatar imageberak ( 2014-06-14 08:41:32 -0600 )edit

like @berak said, move to your own question!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-06-23 08:01:05 -0600 )edit

Question Tools

Stats

Asked: 2013-03-31 09:49:11 -0600

Seen: 3,583 times

Last updated: Jun 14 '14