Browse Source

init

master
diven 2 years ago
parent
commit
f561cc3450
  1. 6
      open-anpr-core/src/main/java/com/visual/open/anpr/core/models/TorchPlateRecognition.java
  2. 12
      open-anpr-core/src/test/java/com/visual/open/anpr/core/extract/PlateExtractorTest.java

6
open-anpr-core/src/main/java/com/visual/open/anpr/core/models/TorchPlateRecognition.java

@ -24,7 +24,7 @@ import java.util.Map;
*/
public class TorchPlateRecognition extends BaseOnnxInfer implements PlateRecognition {
private static float STD_VALUE = 0.193f;
private static float MEAN_VALUE = 0.588f;
private static float MEAN_VALUE = 0.588f * 255;
private final static String[] PLATE_COLOR = new String[]{"黑色", "蓝色", "绿色", "白色", "黄色"};
private final static String PLATE_NAME=
"#京沪津渝冀晋蒙辽吉黑苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云藏陕甘青宁新" +
@ -44,7 +44,7 @@ public class TorchPlateRecognition extends BaseOnnxInfer implements PlateRecogn
imageMat = null == single || single ? image.clone() : splitAndMergePlate(image);
//转换数据为张量
tensor = imageMat.resizeAndNoReleaseMat(168, 48)
.blobFromImageAndDoReleaseMat(1.0/255, new Scalar(MEAN_VALUE, MEAN_VALUE, MEAN_VALUE), true)
.blobFromImageAndDoReleaseMat(1.0/255, new Scalar(MEAN_VALUE, MEAN_VALUE, MEAN_VALUE), false)
.to4dFloatOnnxTensorAndNoReleaseMat(new float[]{STD_VALUE, STD_VALUE, STD_VALUE}, true);
//ONNX推理
output = getSession().run(Collections.singletonMap(getInputName(), tensor));
@ -114,7 +114,7 @@ public class TorchPlateRecognition extends BaseOnnxInfer implements PlateRecogn
private static int[] maxScoreIndex(float[][] result){
int[] indexes = new int[result.length];
for (int i = 0; i < result.length; i++){
int index = -1;
int index = 0;
float max = Float.MIN_VALUE;
for (int j = 0; j < result[i].length; j++) {
if (max < result[i][j]){

12
open-anpr-core/src/test/java/com/visual/open/anpr/core/extract/PlateExtractorTest.java

@ -27,20 +27,22 @@ public class PlateExtractorTest extends BaseTest {
PlateExtractor extractor = new PlateExtractorImpl(torchPlateDetection, torchPlateRecognition);
String imagePath = "open-anpr-core/src/test/resources/images";
// String imagePath = "/Users/diven/workspace/pycharm/github/Chinese_license_plate_detection_recognition/imgs1/image001.jpg";
Map<String, String> map = getImagePathMap(imagePath);
for(String fileName : map.keySet()) {
String imageFilePath = map.get(fileName);
System.out.println(imageFilePath);
Mat image = Imgcodecs.imread(imageFilePath);
long s = System.currentTimeMillis();
long startTime = System.currentTimeMillis();
ExtParam extParam = ExtParam.build()
.setTopK(20)
.setScoreTh(0.3f)
.setIouTh(0.5f);
//推理
PlateImage plateImage = extractor.extract(ImageMat.fromCVMat(image), extParam, new HashMap<>());
System.out.println("cost:" + (System.currentTimeMillis()-startTime));
List<PlateInfo> plateInfos = plateImage.PlateInfos();
//可视化
DrawImage drawImage = DrawImage.build(imageFilePath);
for(PlateInfo plateInfo: plateInfos){
//画框
@ -64,9 +66,9 @@ public class PlateExtractorTest extends BaseTest {
PlateInfo.ParseInfo parseInfo = plateInfo.parseInfo;
int fonSize = Float.valueOf(plateInfo.box.width() / parseInfo.plateNo.length() * 1.4f).intValue();
drawImage.drawText(parseInfo.plateNo,
new DrawImage.Point((int)points[0].x, (int)points[0].y-fonSize*2), fonSize, Color.RED);
new DrawImage.Point((int)points[0].x, (int)points[0].y-(int)(fonSize*2.2)), fonSize, Color.RED);
drawImage.drawText((plateInfo.single ? "单排" : "双排") + ":" + parseInfo.plateColor,
new DrawImage.Point((int)points[0].x, (int)points[0].y-fonSize), fonSize, Color.RED);
new DrawImage.Point((int)points[0].x, (int)points[0].y-(int)(fonSize*1.2)), fonSize, Color.RED);
}
//show
ImageMat.fromCVMat(drawImage.toMat()).imShow();

Loading…
Cancel
Save