标签:java opencv 方法 pat target sub 透明 读取 read
javaCV图像处理系列:
1、车牌检测(支持图片中含有单车牌和多车牌检测)
2、车牌定位
3、车牌字符识别
4、千份测试单次检测识别完成平均耗时39ms,准确率99.9%
github项目地址:https://github.com/eguid/vlpr4j
注意:由于授权协议具有传染性,本项目采用GPL v2.0与ODL(Open Database License)授权协议,本项目不适用于任何商业性行为,包括销售或者赠送。
package cc.eguid.charsocr; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.DataBuffer; import java.awt.image.DataBufferByte; import java.awt.image.SampleModel; import java.math.BigDecimal; import java.util.Vector; import org.bytedeco.javacpp.opencv_imgcodecs; import org.bytedeco.javacpp.Pointer; import org.bytedeco.javacpp.opencv_core; import org.bytedeco.javacpp.opencv_core.CvType; import org.bytedeco.javacpp.opencv_core.CvTypeInfo; import org.bytedeco.javacpp.opencv_core.Mat; import cc.eguid.charsocr.core.CharsRecognise; import cc.eguid.charsocr.core.PlateDetect; /** * 车牌识别 * @author eguid * */ public class PlateRecognition { static PlateDetect plateDetect =null; static CharsRecognise cr=null; static{ plateDetect=new PlateDetect(); plateDetect.setPDLifemode(true); cr = new CharsRecognise(); } /** * 单个车牌识别 * @param mat * @return */ public static String plateRecognise(Mat mat){ Vector<Mat> matVector = new Vector<Mat>(1); if (0 == plateDetect.plateDetect(mat, matVector)) { if(matVector.size()>0){ return cr.charsRecognise(matVector.get(0)); } } return null; } /** * 多车牌识别 * @param mat * @return */ public static String[] mutiPlateRecognise(Mat mat){ PlateDetect plateDetect = new PlateDetect(); plateDetect.setPDLifemode(true); Vector<Mat> matVector = new Vector<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; } /** * 单个车牌识别 * @param mat * @return */ public static String plateRecognise(String imgPath){ Mat src = opencv_imgcodecs.imread(imgPath); return plateRecognise(src); } /** * 多车牌识别 * @param mat * @return */ public static String[] mutiPlateRecognise(String imgPath){ Mat src = opencv_imgcodecs.imread(imgPath); return mutiPlateRecognise(src); } public static void main(String[] args){ int sum=100; int errNum=0; int sumTime=0; long longTime=0; for(int i=sum;i>0;i--){ String imgPath = "res/image/test_image/plate_judge.jpg"; Mat src = opencv_imgcodecs.imread(imgPath); long now =System.currentTimeMillis(); String ret=plateRecognise(src); System.err.println(ret); long s=System.currentTimeMillis()-now; if(s>longTime){ longTime=s; } sumTime+=s; if(!"川A0CP56".equals(ret)){ errNum++; } } System.err.println("总数量:"+sum); System.err.println("单次最长耗时:"+longTime+"ms"); 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+"%"); } }
javacpp-opencv图像处理系列:国内车辆牌照检测识别系统(万份测试车牌识别准确率99.7%以上,单次平均耗时39ms)
标签:java opencv 方法 pat target sub 透明 读取 read
原文地址:http://www.cnblogs.com/eguid/p/6986215.html