finding the highest / lowest contours in a ROI

asked 2016-01-23 11:30:06 -0500

lm1993 gravatar image

updated 2016-01-23 13:49:38 -0500

I am developing an app that searches for contours within a region of interest. I only want to display the top and bottom contours. I have managed to find the contours but i only want to display the highest and lowest contours. I have made a for loop that loops through the contours but i am unsure how to progress.. anyone got any ideas?

Thankyou in advance

RoiMat= image.submat(rect.y, rect.y + rect.height, rect.x, rect.x + rect.width);

                    Imgproc.cvtColor(RoiMat, RoiMat, Imgproc.COLOR_RGB2GRAY);
                    equalizeHist(RoiMat, RoiMat);
                    Imgproc.GaussianBlur(RoiMat, RoiMat, new Size(5, 5), 0);
                    Imgproc.threshold(RoiMat, RoiMat, 100, 255, Imgproc.THRESH_BINARY_INV);

                    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
                    Mat hierarchy = new Mat();
                    Imgproc.findContours(RoiMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);


                    for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
                        //search for the highest and lowest contours here and output as points.
Mat contour = contours.get(idx);
                    }
edit retag flag offensive close merge delete

Comments

try to understand hierarchy

sturkmen gravatar imagesturkmen ( 2016-01-23 11:55:45 -0500 )edit

could you explain highest and lowest contours. if you want to find biggest and smallest contours take a look at http://answers.opencv.org/question/81730

sturkmen gravatar imagesturkmen ( 2016-01-23 13:58:42 -0500 )edit

apologies for my slow reply. yeah i want to find the highest point and lowest point in the contours and output it as a Point

lm1993 gravatar imagelm1993 ( 2016-01-24 09:29:41 -0500 )edit