How to get fixed sized ROI from findCountours

asked 2018-04-08 07:01:28 -0500

I have code like this

List<MatOfPoint> kontur = new LinkedList<>();

    Imgproc.findContours(DaerahKulit, kontur, hirarki, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

    for(int i=0; i < kontur.size(); i++){
        areakontur = Imgproc.contourArea(kontur.get(i));

        rek = Imgproc.boundingRect(kontur.get(i));
        if(areakontur > konturterbesar){
            konturterbesar = areakontur;
            indeksterbesar = i;

            //Imgproc.drawContours(matframe, kontur, i, new Scalar(0, 255, 0), 3);
    roieuy = new Mat(inputFrame, rek); --> this is unfixed size Rect

where rek are Rect datatype. How can i get fixed size from rek for my predict SVM this is code for my predict SVM

    //Mat ROI = new Mat(matframe, rek);
    Imgproc.resize(roieuy, roieuy, new Size(200, 200));
    Imgproc.cvtColor(roieuy, roieuy, Imgproc.COLOR_BGR2GRAY);
    roieuy.convertTo(roieuy, CvType.CV_8UC1);
    MatOfFloat deskritor = new MatOfFloat();
    d.compute(roieuy, deskritor);
    double hasil = baru.predict(deskritor.reshape(1, 1));

But actually this code runs well but get the problem from unfixed width dan height Rect it's can cause my predict SVM getting wrong predict. How can i solved this ? thanks in advanced !

edit retag flag offensive close merge delete