Attention! This forum will be made read-only by Dec-20. Please migrate to https://forum.opencv.org. Most of existing active users should've received invitation by e-mail.
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Contour opencv bigger than contour of threshold ?

Threshold image : C:\fakepath\thresh.png Contour image: C:\fakepath\contour.png

This is my code:

public class Test1 { public static void main(String[] args) { JFileChooser f = new JFileChooser("C:\Users\DinhThap\Documents\NetBeansProjects\LicensePlateRecognition"); int result = f.showOpenDialog(f);//show dialog box to choose files File myfile = null; String path = ""; if (result == 0) { myfile = f.getSelectedFile();//selected file taken to myfile path = myfile.getAbsolutePath();//get the path of the file } Imshow.showMultiple("Gray", opencv_imgcodecs.cvLoadImage(path)); opencv_core.Mat grayScale = ImageOpenCvUtils.toGray(opencv_imgcodecs.imread(path));

    //opencv_core.Mat grayScale = ImageOpenCvUtils.toMat(ImageOpenCvUtils.toGray(opencv_imgcodecs.cvLoadImage(path)));

    Imshow.showMultiple("Gray", grayScale);
    opencv_core.Mat maximizeContrast = ImageOpenCvUtils.maximizeContrastMat(grayScale, 1);

    //opencv_core.Mat gaussianFilter = ImageOpenCvUtils.toGaussianFilterMat(maximizeContrast, Conf.GAUSSIAN_SMOOTH_FILTER_SIZE, 0);
    opencv_core.Mat gaussianFilter = new opencv_core.Mat();
    opencv_imgproc.bilateralFilter(maximizeContrast, gaussianFilter, 9, 18, 9/2);

    opencv_core.Mat threshold = ImageOpenCvUtils.toAdaptiveThresholdMat(gaussianFilter, 19, 9);
    Imshow.showMultiple("Gray", threshold);
    List<CharMat> listOfPossibleChar = DetectPlateMat.getPossibleCharsInScene(threshold);
    opencv_core.Mat imgContours = new opencv_core.Mat(threshold.size(), opencv_core.CV_8UC3, opencv_core.Scalar.BLACK); //opencv_imgproc.CV_AA
    opencv_imgproc.drawContours(imgContours, convertListToArrMat(listOfPossibleChar), -1, opencv_core.Scalar.WHITE);
    Imshow.showMultiple("Gaussian", imgContours);


}

}

Contour opencv bigger than contour of threshold ?

Threshold image : C:\fakepath\thresh.png Contour image: C:\fakepath\contour.png

This is my code:

public class Test1 { public static void main(String[] args) { JFileChooser f = new JFileChooser("C:\Users\DinhThap\Documents\NetBeansProjects\LicensePlateRecognition"); int result = f.showOpenDialog(f);//show dialog box to choose files File myfile = null; String path = ""; if (result == 0) { myfile = f.getSelectedFile();//selected file taken to myfile path = myfile.getAbsolutePath();//get the path of the file } Imshow.showMultiple("Gray", opencv_imgcodecs.cvLoadImage(path)); opencv_core.Mat grayScale = ImageOpenCvUtils.toGray(opencv_imgcodecs.imread(path));

    //opencv_core.Mat grayScale = ImageOpenCvUtils.toMat(ImageOpenCvUtils.toGray(opencv_imgcodecs.cvLoadImage(path)));

    Imshow.showMultiple("Gray", grayScale);
    opencv_core.Mat maximizeContrast = ImageOpenCvUtils.maximizeContrastMat(grayScale, 1);

    //opencv_core.Mat gaussianFilter = ImageOpenCvUtils.toGaussianFilterMat(maximizeContrast, Conf.GAUSSIAN_SMOOTH_FILTER_SIZE, 0);
    opencv_core.Mat gaussianFilter = new opencv_core.Mat();
    opencv_imgproc.bilateralFilter(maximizeContrast, gaussianFilter, 9, 18, 9/2);

    opencv_core.Mat threshold = ImageOpenCvUtils.toAdaptiveThresholdMat(gaussianFilter, 19, 9);
    Imshow.showMultiple("Gray", threshold);
    List<CharMat> listOfPossibleChar = DetectPlateMat.getPossibleCharsInScene(threshold);
    opencv_core.Mat imgContours = new opencv_core.Mat(threshold.size(), opencv_core.CV_8UC3, opencv_core.Scalar.BLACK); //opencv_imgproc.CV_AA
    opencv_imgproc.drawContours(imgContours, convertListToArrMat(listOfPossibleChar), -1, opencv_core.Scalar.WHITE);
    Imshow.showMultiple("Gaussian", imgContours);


}

}