|
|
|
@ -6,6 +6,7 @@ import static org.bytedeco.javacpp.opencv_core.*;
|
|
|
|
|
import static org.bytedeco.javacpp.opencv_imgproc.*;
|
|
|
|
|
|
|
|
|
|
import com.yuxue.constant.Constant;
|
|
|
|
|
import org.bytedeco.javacpp.opencv_highgui;
|
|
|
|
|
import org.bytedeco.javacpp.opencv_imgcodecs;
|
|
|
|
|
|
|
|
|
|
import org.bytedeco.javacpp.opencv_core.CvPoint2D32f;
|
|
|
|
@ -17,7 +18,6 @@ import org.bytedeco.javacpp.opencv_core.RotatedRect;
|
|
|
|
|
import org.bytedeco.javacpp.opencv_core.Scalar;
|
|
|
|
|
import org.bytedeco.javacpp.opencv_core.Size;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 车牌定位
|
|
|
|
|
* @author yuxue
|
|
|
|
@ -117,12 +117,16 @@ public class PlateLocate {
|
|
|
|
|
// 高斯模糊。Size中的数字影响车牌定位的效果。
|
|
|
|
|
GaussianBlur(src, src_blur, new Size(gaussianBlurSize, gaussianBlurSize), 0, 0, BORDER_DEFAULT);
|
|
|
|
|
if (debug) {
|
|
|
|
|
//opencv_highgui.imshow("Plate Detected", src_blur);
|
|
|
|
|
//opencv_highgui.waitKey(0);
|
|
|
|
|
opencv_imgcodecs.imwrite(tempPath + "debug_GaussianBlur.jpg", src_blur);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert it to gray 将图像进行灰度化
|
|
|
|
|
cvtColor(src_blur, src_gray, CV_RGB2GRAY);
|
|
|
|
|
if (debug) {
|
|
|
|
|
//opencv_highgui.imshow("Plate Detected", src_gray);
|
|
|
|
|
//opencv_highgui.waitKey(0);
|
|
|
|
|
opencv_imgcodecs.imwrite(tempPath + "debug_gray.jpg", src_gray);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -144,6 +148,8 @@ public class PlateLocate {
|
|
|
|
|
addWeighted(abs_grad_x, SOBEL_X_WEIGHT, abs_grad_y, SOBEL_Y_WEIGHT, 0, grad);
|
|
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
|
//opencv_highgui.imshow("Plate Detected", grad);
|
|
|
|
|
//opencv_highgui.waitKey(0);
|
|
|
|
|
opencv_imgcodecs.imwrite(tempPath + "debug_Sobel.jpg", grad);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -153,6 +159,8 @@ public class PlateLocate {
|
|
|
|
|
threshold(grad, img_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
|
|
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
|
//opencv_highgui.imshow("Plate Detected", img_threshold);
|
|
|
|
|
//opencv_highgui.waitKey(0);
|
|
|
|
|
opencv_imgcodecs.imwrite(tempPath + "debug_threshold.jpg", img_threshold);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -162,6 +170,8 @@ public class PlateLocate {
|
|
|
|
|
morphologyEx(img_threshold, img_threshold, MORPH_CLOSE, element);
|
|
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
|
//opencv_highgui.imshow("Plate Detected", img_threshold);
|
|
|
|
|
//opencv_highgui.waitKey(0);
|
|
|
|
|
opencv_imgcodecs.imwrite(tempPath + "debug_morphology.jpg", img_threshold);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -178,6 +188,8 @@ public class PlateLocate {
|
|
|
|
|
// 将轮廓描绘到图上输出
|
|
|
|
|
drawContours(result, contours, -1, new Scalar(0, 0, 255, 255));
|
|
|
|
|
opencv_imgcodecs.imwrite(tempPath + "debug_Contours.jpg", result);
|
|
|
|
|
//opencv_highgui.imshow("Plate Detected", result);
|
|
|
|
|
//opencv_highgui.waitKey(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start to iterate to each contour founded
|
|
|
|
@ -275,6 +287,7 @@ public class PlateLocate {
|
|
|
|
|
|
|
|
|
|
Mat resultResized = new Mat();
|
|
|
|
|
resultResized.create(HEIGHT, WIDTH, TYPE);
|
|
|
|
|
//大小调整,训练之前要保证图像大小一致
|
|
|
|
|
resize(img_crop, resultResized, resultResized.size(), 0, 0, INTER_CUBIC);
|
|
|
|
|
if (debug) {
|
|
|
|
|
opencv_imgcodecs.imwrite(tempPath + "debug_resize_" + index + ".jpg", resultResized);
|
|
|
|
|