主函数main如何写才能识别多张车牌public static String[] multiPlateRecognise(opencv_core.Mat mat) { PlateDetect plateDetect = new PlateDetect(); plateDetect.setPDLifemode(true); Vector<opencv_core.Mat> matVector = new Vector<opencv_core.Mat>(10); if (0 == plateDetect.plateDetect(mat, matVector)) { CharsRecognise cr = new CharsRecognise(); String[] results = new String[matVector.size()]; for (int i = 0; i < matVector.size(); ++i) { String result = cr.charsRecognise(matVector.get(i)); results[i] = result; } return results; } return null; }主函数如下: public static void main(String[] args) { //使用了以下算法 //基于模板匹配的字符识别算法 //二值化算法 //边缘检测算法 //形态学操作 //直方图均衡化算法 //训练分类模型算法 //原图 int sum = imgPaths.length; int errNum = 0; int sumTime = 0; long longTime = 0; String[] imgPaths = {"res/image/test_image/plate_locate.jpg","res/image/test_image/test.jpg", "res/image/test_image/plate_detect.jpg"}; opencv_core.Mat src = opencv_imgcodecs.imread(imgPath); String ret = Arrays.toString(multiPlateRecognise(src)); long now = System.currentTimeMillis(); System.err.println(ret); long s = System.currentTimeMillis() - now; if (s > longTime) { longTime = s; } sumTime += s; System.out.println("识别车牌" + ret); if (!"苏EUK722".equals(ret)) { errNum++; } if (!"苏AOCP56".equals(ret)) { errNum++; } if (!"沪BS781".equals(ret)) { errNum++; } BigDecimal errSum = new BigDecimal(errNum); BigDecimal sumNum = new BigDecimal(sum); BigDecimal c = sumNum.subtract(errSum).divide(sumNum).multiply(new BigDecimal(100)); System.err.println("总耗时:" + sumTime + "ms,平均处理时长:" + sumTime / sum + "ms,错误数量:" + errNum + ",正确识别率:" + c + "%"); } }
时间: 2024-04-02 15:34:32 浏览: 59
车牌识别-主程序
3星 · 编辑精心推荐
首先,需要将多张车牌的路径存储在一个数组中,例如:
String[] imgPaths = {"res/image/test_image/plate_locate.jpg","res/image/test_image/test.jpg", "res/image/test_image/plate_detect.jpg"};
然后,在主函数中使用一个循环,遍历数组中的每一张车牌图片,调用multiPlateRecognise()方法进行车牌识别,并统计正确率和耗时等信息。示例代码如下:
int sum = imgPaths.length;
int errNum = 0;
int sumTime = 0;
long longTime = 0;
for (int i = 0; i < sum; i++) {
opencv_core.Mat src = opencv_imgcodecs.imread(imgPaths[i]);
String ret = Arrays.toString(multiPlateRecognise(src));
long now = System.currentTimeMillis();
System.err.println(ret);
long s = System.currentTimeMillis() - now;
if (s > longTime) {
longTime = s;
}
sumTime += s;
System.out.println("识别车牌" + ret);
if (!"苏EUK722".equals(ret)) {
errNum++;
}
if (!"苏AOCP56".equals(ret)) {
errNum++;
}
if (!"沪BS781".equals(ret)) {
errNum++;
}
}
BigDecimal errSum = new BigDecimal(errNum);
BigDecimal sumNum = new BigDecimal(sum * 3);
BigDecimal c = sumNum.subtract(errSum).divide(sumNum).multiply(new BigDecimal(100));
System.err.println("总耗时:" + sumTime + "ms,平均处理时长:" + sumTime / (sum * 3) + "ms,错误数量:" + errNum + ",正确识别率:" + c + "%");
需要注意的是,由于每张车牌图片都需要识别三次,所以正确率的计算需要乘以3。
阅读全文