Hi I started using JavaCV two days ago,
I m trying to make an ANPR Open Source System at my git repository under Java SE and Maven.
I have detected my plate rectangle and now I'm trying to prepare a good image for OCR reading.
the original image :
Right now I have obtained this image :
Is there any way to turn my plate numbers black using JavaCv ? I don't have the slightest idea how to do so using javacv functions .
here I give you the methods that are producing this result :
first I call this after a blur
public void toB_A_W(JLabel jLabel){
Mat rgbImage = Imgcodecs.imread(original);
Mat destination = new Mat(rgbImage.rows(), rgbImage.cols(), rgbImage.type());
// l objectif et de corriger les erreur de la transformation en noire et blan
int dilation_size = 2;
// la matrice de la dilatation on cherche a dilater en forme de rectange ( Imgproc.MORPH_RECT )
Mat element1 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(dilation_size + 1, dilation_size + 1));
// on dilate l image
Imgproc.dilate(rgbImage, destination, element1);
Mat labImage = new Mat();
cvtColor(destination, labImage, Imgproc.COLOR_BGR2GRAY);
Imgcodecs.imwrite(ocrReadFrom, labImage);
jLabel.setIcon(new ImageIcon(ocrReadFrom));
JOptionPane.showConfirmDialog(null, "");
}
then I call this :
public void toB_W(JLabel jLabelBlackAndWhiteImage) {
// cella est l image de l ocr
smouthedImage = opencv_imgcodecs.cvLoadImage(ocrReadFrom);
blackAndWhiteImageOCR = opencv_core.IplImage.create(smouthedImage.width(),
smouthedImage.height(), IPL_DEPTH_8U, 1);
// la fonction qui va executé la transformation en noire et blan
System.out.println("0");
//cvAdaptiveThreshold(smouthedImage, smouthedImage, 255, CV_ADAPTIVE_THRESH_GAUSSIAN_C, opencv_imgproc.CV_THRESH_MASK, 15, -2);
opencv_imgproc.cvSmooth(smouthedImage, smouthedImage);
System.out.println("1");
cvCvtColor(smouthedImage, blackAndWhiteImageOCR, CV_BGR2GRAY);
System.out.println("2");
cvAdaptiveThreshold(blackAndWhiteImageOCR, blackAndWhiteImageOCR, 255, CV_ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY_INV, 17, -4);
System.out.println("3");
opencv_imgproc.cvSmooth(blackAndWhiteImageOCR, blackAndWhiteImageOCR);
// fin de la transformation
cvSaveImage(ocrReadFrom, blackAndWhiteImageOCR);
...}
Thanks
You want to fill the numbers, you could have considered performing binary threshold rather than adaptive threshold.
I chose a threshold level of 40 to make the numbers distinct.