What am I doing wrong?. I don't get to translate the ROI of one Image to a new one.

55 views
Skip to first unread message

Pedro Evaristo Gonzalez Sanchez

unread,
May 29, 2012, 6:58:55 PM5/29/12
to android...@googlegroups.com

I get the same Image as the original, but I don't get a bigger one with the ROI in the center. Maybe it's easy, but I don't find the problem.


for( int index = 0; index < contours.size();index++ ){      

        Mat contour = contours.get(index); 

            double contourArea =Imgproc.contourArea(contour); 

                    

            if( contourArea > max) {

            max = Math.max(max, contourArea);

            indexMax = index;

            }

        }

        

        if( indexMax > -1){ 

        

         Imgproc.threshold(mCellCopy, mCellCopy, 128, 255, Imgproc.THRESH_BINARY);

       

        // ROI source 

        Converters.Mat_to_vector_Point(contours.get(indexMax), contourPoints); 

        boundingRect = Imgproc.boundingRect(contourPoints); 

        Mat mROISource = new Mat(boundingRect.width, boundingRect.height, CvType.CV_8UC1, new Scalar(0));

      

        mROISource = mCellCopy.submat(boundingRect);

       

        //Img destine

         Mat mCentredNumber = new Mat(100,100, CvType.CV_8UC1, new Scalar(255)); 

        

        //ROI destine in the center of the new Image

        int x = (int) (Math.floor(mCentredNumber.size().width/2.0f)); - boundingRect.width/2; 

        int y = (int) (Math.floor(mCentredNumber.size().height/2.0f)); - boundingRect.height/2;

        Rect ROI = new Rect(x,y,boundingRect.width,boundingRect.height);

        

        // Referencing ROI destine

        Mat mROIC = mCentredNumber.submat(ROI);

        

        // ROI source to ROI destine

        mROISource.copyTo(mROIC);

Highgui.imwrite("/mnt/sdcard/CellCentred/"+i+j+".png", mROIC);

Thank you.

Reply all
Reply to author
Forward
0 new messages