这是一个基于spring boot + maven + opencv 实现的图像识别及训练的demo项目
包含车牌识别、人脸识别等功能,贯穿样本处理、模型训练、图像处理、对象检测、对象识别等技术点
java语言的深度学习项目,在整个开源社区来说都相对较少;
拥有完整的训练过程、检测、识别过程的开源项目更是少之又少!!
b/s 架构,前端html + requirejs,后端java
数据库使用 sqlite3.0
接口文档使用swagger 2.0
参考了easypr c++项目、以及fan-wenjie的easypr-java项目;同时查阅了部分opencv官方4.0.1版本c++的源码,结合个人对java语言的理解,整理出当前项目
liuruoze/easypr
fan-wenjie/easypr-java
opencv官方
车牌识别
黄牌识别
绿牌识别
夜间识别
图片提取工具
人脸识别
训练
接口文档
高斯模糊:
图像灰度化:
sobel 算子:
图像二值化:
图像闭操作:
二值图像降噪:
提取外部轮廓:
外部轮廓筛选:
切图:
重置切图尺寸:
车牌检测结果:
车牌检测结果:
debug_char_threshold:
debug_char_clearliuding:
debug_specmat:
debug_chinemat:
debug_char_auxroi:
package com.yuxue.rvice.impl; import java.io.file;import java.util.list;import java.util.map;import java.util.t;import java.util.vector; import org.opencv.core.core;import org.opencv.core.cvtype;import org.opencv.core.mat;import org.opencv.imgcodecs.imgcodecs;import org.opencv.imgproc.imgproc;import org.springframework.beans.factory.annotation.autowired;import org.springframework.stereotype.rvice;import org.springframework.transaction.annotation.propagation;import org.springframework.transaction.annotation.transactional; import com.alibaba.druid.util.stringutils;import com.alibaba.fastjson.jsonobject;import com.google.common.collect.lists;import com.google.common.collect.maps;import com.google.common.collect.ts;import com.yuxue.constant.constant;import com.yuxue.entity.platefileentity;import com.yuxue.entity.tempplatefileentity;import com.yuxue.enumtype.platecolor;import com.yuxue.mapper.platefilemapper;import com.yuxue.mapper.tempplatefilemapper;import com.yuxue.rvice.platervice;import com.yuxue.util.fileutil;import com.yuxue.util.generateidutil;import com.yuxue.util.plateutil; @rvicepublic class platerviceimpl implements platervice { @autowired private platefilemapper platefilemapper; @autowired private tempplatefilemapper tempplatefilemapper; static { system.loadlibrary(core.native_library_name); } @override @transactional(propagation = propagation.required) public object refreshfileinfo() { file badir = new file(constant.default_dir); if(!badir.exists() || !badir.isdirectory()) { return null; } list<tempplatefileentity> resultlist = lists.newarraylist(); // 获取badir下第一层级的目录, 仅获取文件夹,不递归子目录,遍历 list<file> folderlist = fileutil.listfile(badir, ";", fal); folderlist.parallelstream().foreach(folder -> { if(!folder.getname().equals("temp")) { // 遍历每一个文件夹, 递归获取文件夹下的图片 list<file> imglist = fileutil.listfile(folder, constant.default_type, true); if(null != imglist && imglist.size() > 0) { imglist.parallelstream().foreach(n->{ tempplatefileentity entity = new tempplatefileentity(); entity.tfilepath(n.getabsolutepath().replaceall("\\\\", "/")); 寒假安全教育 entity.tfilename(n.getname()); entity.tfiletype(n.getname().substring(n.getname().lastindexof(".") + 1)); resultlist.add(entity); }); } } }); tempplatefilemapper.turncatetable(); tempplatefilemapper.batchinrt(resultlist); tempplatefilemapper.updatefileinfo(); return 1; } @override public object recogni(string filepath, boolean rerecogni) { filepath = filepath.replaceall("\\\\", "/"); file f = new file(filepath); platefileentity entity = null; map<string, object> parammap = maps.newhashmap(); parammap.put("filepath", filepath); list<platefileentity> list= platefilemapper.lectbycondition(parammap); if(null == list || list.size() <= 0) { if(fileutil.checkfile(f)) { entity = new platefileentity(); entity.tfilename(f.getname()); entity.tfilepath(f.getabsolutepath().replaceall("\\\\", "/")); entity.tfiletype(f.getname().substring(f.getname().lastindexof(".") + 1)); platefilemapper.inrtlective(entity); } rerecogni = true; } el { entity = list.get(0); } if(rerecogni || stringutils.impty(entity.gettemppath())) { dorecogni(f, entity); // 重新识别 entity = platefilemapper.lectbyprimarykey(entity.getid()); // 重新识别之后,重新获取一下数据 } // 查询debug文件 if(!stringutil行政事业单位会计制度s.impty(entity.gettemppath())) { vector<string> debugfiles = new vector<string>(); fileutil.getfiles(entity.gettemppath(), debugfiles); entity.tdebugfiles(debugfiles); } return entity; } @override public object recogniall() { // 查询到还没有进行车牌识别的图片 list<platefileentity> list = platefilemapper.getunrecognilist(); list.parallelstream().foreach(n->{ file f = new file(n.getfilepath()); if(fileutil.checkfile(f)) { dorecogni(f, n); } }); return 1; } /** * 单张图片 车牌识别 * 拷贝文件到临时目录 * 过程及结果更新数据库 * @param f * @param e * @return */ public object dorecogni(file f, platefileentity e) { if(!f.exists()) { return null; } string ct = generateidutil.getstrid(); string targetpath = constant.default_temp_dir + ct + (f.getname().substring(f.getname().lastindexof("."))); fileutil.copyandrename(f.getabsolutepath(), targetpath); // 拷贝文件并且重命名 // 创建临时目录, 存放过程图片 string temppath = constant.default_temp_dir + ct + "/"; fileutil.createdir(temppath); e.ttemppath(temppath); boolean debug = fal; vector<mat> dst = new vector<mat>(); plateutil.getplatemat(targetpath, dst, debug, temppath); t<string> plates = ts.newhasht(); dst.stream().foreach(inmat -> { platecolor color = plateutil.getplatecolor(inmat, true, fal, temppath); string plate = plateutil.charsgment(inmat, color, debug, temppath); plates.add("<" + plate + "," + color.desc + ">"); }); e.trecoplate(plates.tostring()); new file(targetpath).delete(); // 删除拷贝的临时文件 platefilemapper.updatebyprimarykeylective(e); return 1; } @override public object getimginfo(string imgpath) { map<string, object> result = maps.newhashmap(); string ct = generateidutil.getstrid(); file f = new file(imgpath); if(f.exists()) { string targetpath = constant.default_temp_dir + ct + (f.getname().substring(f.getname().lastindexof("."))); fileutil.copyandrename(f.getabsolutepath(), targetpath); result.put("targetpath", targetpath); // 返回临时路径给前端 // 获取图片的基本信息 mat inmat = imgcodecs.imread(targetpath); result.put("rows", inmat.rows()); result.put("cols", inmat.cols()); } return result; } @override public object gethsvvalue(string imgpath, integer row, integer col) { map<string, object> result = maps.newhashmap(); mat inmat = imgcodecs.imread(imgpath); double[] rgb = inmat.get(row, col); result.put("rgb", jsonobject.tojsonstring(rgb)); mat dst = new mat(inmat.rows(), inmat.cols(), cvtype.cv_32fc3); imgproc.cvtcolor(inmat, dst, imgproc.color_bgr2hsv); // 转到hsv空间进行处理 double[] hsv = dst.get(row, col); result.put("hsv", (int)hsv[0] + ", " + (int)hsv[1] + ", " + (int)hsv[2]); return result; } }
package com.znz.rvice.impl; import com.znz.rvice.platetypervice;import com.znz.entity.platetypeentity;import com.znz.mapper.platetypemapper; import com.github.pagehelper.pagehelper;import com.github.pagehelper.pageinfo; import org.springframework.transaction.annotation.transactional;import org.springframework.transaction.annotation.propagation; import org.springframework.beans.factory.annotation.autowired;import org.springframework.stereotype.rvice;import java.util.hashmap;import java.util.map;import java.util.list; /** * 服务实现层 * @author znz * @date 2020-09-30t16:54:41.823 */@rvicepublic class platetyperviceimpl implements platetypervice { @autowired private platetypemapper platetypemapper; @override public platetypeentity getbyprimarykey(integer id) { platetypeentity entity = platetypemapper.lectbyprimarykey(id); return entity; } @override public pageinfo<platetypeentity> querybypage(integer pageno, integer pagesize, map<string, object> map) { pagehelper.startpage(pageno, pagesize);pageinfo<platetypeentity> page = new pageinfo(platetypemapper.lectbycondition(map));return page; } @override public list<platetypeentity> querybycondition(map<string, object> map) {return platetypemapper.lectbycondition(map); } @override @transactional(propagation = propagation.required) public map<string, object> save(platetypeentity platetypeentity) { platetypeentity.tid(0); platetypemapper.inrtlective(platetypeentity); map<string, object> result = new hashmap<>(); result.put("id" , platetypeentity.getid()); return result; } @override@transactional(propagation = propagation.required)public integer deletebyid(integer id){return platetypemapper.deletebyprimarykey(id);} @override @transactional(propagation = propagation.required) public integer updatebyid(platetypeentity platetypeentity) { if(null == platetypeentity || platetypeentity.getid() <= 0){ return 0; } return platetypemapper.updatebyprimarykeylective(platetypeentity); } }
package com.znz.rvice.impl; import com.github.pagehelper.pagehelper;import com.github.pagehelper.pageinfo;import com.google.common.collect.lists;import com.google.common.collect.maps;import com.znz.entity.systemmenuentity;import com.znz.mapper.systemmenumapper;import com.znz.rvice.systemmenurvice; import org.springframework.transaction.annotation.transactional;import org.springframework.transaction.annotation.propagation; import org.springframework.beans.factory.annotation.autowired;import org.springframework.stereotype.rvice;import java.util.hashmap;import java.util.list;import java.util.map; /** * 服务实现层 * @author znz * @date 2021-06-20 16:15:23 */@rvicepublic class systemmenurviceimpl implements systemmenurvice { @autowired private systemmenumapper systemmenumapper; @override public systemmenuentity getbyprimarykey(integer id) { systemmenuentity entity = systemmenumapper.lectbyprimarykey(id); return entity; } @override public pageinfo<systemmenuentity> querybypage(integer pageno, integer pagesize, map<string, object> map) { pagehelper.startpage(pageno, pagesize);pageinfo<systemmenuentity> page = new pageinfo(systemmenumapper.lectbycondition(map));return page; } @overridepublic list<systemmenuentity> querybycondition(map<string, object> map) {return systemmenumapper.lectbycondition(map);} @override @transactional(propagation = propagation.required) public map<string, object> save(systemmenuentity entity) { entity.tid(0); systemmenumapper.inrtlective(entity); map<string, object> result = new hashmap<>(); result.put("id" , entity.getid()); return result; } @override@transactional(propagation = propagation.required)public integer deletebyid(integer id){return systemmenumapper.deletebyprimarykey(id);} @overr趣味数学小故事ide @transactional(propagation = propagation.required) public integer updatebyid(systemmenuentity systemmenuentity) { if(null == systemmenuentity || systemmenuentity.getid() <= 0){ return 0; } return systemmenumapper.updatebyprimarykeylective(systemmenuentity); }@override public object geturmenu() { map<string, object> map = maps.newhashmap(); map.put("showflag", 1); list<systemmenuentity> menus = systemmenumapper.lectbycondition(map); //按层级封装,最多三级 map<string, object> result = maps.newhashmap(); result.put("first", menus.stream().filter(n -> { return n.getmenulevel() == 1; })); result.put("cond", menus.stream().filter(n -> { return n.getmenulevel() == 2; })); result.put("third", menus.stream().filter(n -> { return n.getmenulevel() == 3; })); return resul自学英语怎么学t; } }
package com.znz.rvice.impl; import java.io.file;import java.util.list; import org.springframework.stereotype.rvice; import com.alibaba.druid.util.stringutils;import com.alibaba.fastjson.jsonobject;import com.google.common.collect.lists;import com.znz.constant.constant;import com.znz.exception.resultreturnexception;import com.znz.rvice.filervice;import com.znz.util.fileutil; @rvicepublic class filerviceimpl implements filervice { @override public list<jsonobject> getfiletreebydir(string rootpath, string dir, string typefilter) { if(stringutils.impty(dir)){ if(stringutils.impty(rootpath)){ dir = constant.default_dir; } el { dir = rootpath; } } if(stringutils.impty(typefilter)){ typefilter = constant.default_type; } file f = new file(dir); list<file> list = fileutil.listfile(f, typefilter, fal); list<jsonobject> result = lists.newarraylist(); list.stream().foreach(n->{ jsonobject jo = new jsonobject(); jo.put("id", n.getabsolutepath()); jo.put("pid", n.getparentfile().getabsolutepath()); jo.put("filepath", n.getabsolutepath()); jo.put("filename", n.getname()); jo.put("isdir", n.isdirectory()); result.add(jo); }); return result; } @override public file readfile(string filepath) { file f = new file(filepath); if(!f.exists() || f.isdirectory()) { throw new resultreturnexception("filepath参数异常,找不到指定的文件: " + filepath); } if(!f.exists() || f.isdirectory()) { throw new resultreturnexception("读取图片异常:" + f.getname()); } return f; } }
以上就是opencv创建车牌图片识别系统方法详解的详细内容,更多关于opencv车牌图片识别系统的资料请关注www.887551.com其它相关文章!
本文发布于:2023-04-04 11:05:50,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/eee35856d92b9d1142d80fed9aec1839.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Opencv创建车牌图片识别系统方法详解.doc
本文 PDF 下载地址:Opencv创建车牌图片识别系统方法详解.pdf
留言与评论(共有 0 条评论) |