Click here to Skip to main content
15,887,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,i am using the opencv findCountour function in finding the contour and draw the found contour on the image. The code seems to have no issue, however when i try to debug, it show the error that the variable "hierarchy" cannot be be find. I am not sure why is this so, help please, thank you.

The problem seems to be at the Imgproc.java file (this is imported from opencv)whereby the hierarchy is in red(meaning error).

//javadoc: findContours(image, contours, hierarchy, mode, method)
   public static void findContours(Mat image, List<MatOfPoint> contours, Mat mat, int mode, int method)
   {
       Mat contours_mat = new Mat();
       findContours_1(image.nativeObj, contours_mat.nativeObj, hierarchy.nativeObj, mode, method);
       Converters.Mat_to_vector_vector_Point(contours_mat, contours);
       contours_mat.release();
       return;
   }


What I have tried:

part of the findContour code

//find contour
        List<MatOfPoint> contours = new ArrayList<>();
        //Imgproc.findContours(outputImage,contours,new Mat(),Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
        Imgproc.findContours(outputImage,contours, hierarchy,Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
        //draw contour
        Imgproc.drawContours(outputImage,contours,-1,new Scalar(0,255,0));
Posted
Comments
Richard MacCutchan 26-Jun-18 5:57am    
Where is the hierarchy object declared in your code?
Member 13882534 26-Jun-18 21:05pm    
It is being declare in the method, Mat hierarchy = new Mat(); but the same error still exist
Richard MacCutchan 27-Jun-18 3:22am    
Well it is obviously not visible within the scope of the code you have shown above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900