实验37 综合实战:车牌识别

上传人:ba****u6 文档编号:175185571 上传时间:2022-12-19 格式:DOCX 页数:11 大小:62.76KB
收藏 版权申诉 举报 下载
实验37 综合实战:车牌识别_第1页
第1页 / 共11页
实验37 综合实战:车牌识别_第2页
第2页 / 共11页
实验37 综合实战:车牌识别_第3页
第3页 / 共11页
资源描述:

《实验37 综合实战:车牌识别》由会员分享,可在线阅读,更多相关《实验37 综合实战:车牌识别(11页珍藏版)》请在装配图网上搜索。

1、实验三十七 综合实战:车牌识别37.1 实验目的基于MapReduce思想,编写车牌识别程序。实现对江苏某两处监控图片中的车牌的 识别,完成对除江苏省车辆外的外省车辆的统计,并完成对两处监控中套牌车辆的识别, 并得出结果。37.2 实验要求要能理解MapReduce编程思想,会编写MapReduce车牌识别程序,能够利用Java调 用已封装好C+的so动态库完成车牌的识别,然后利用MapReduce完成对车牌的统计和 对套牌车的识别。最后将其执行并分析执行过程。37.3 实验步骤37.3.1 编写程序对于外省车牌的统计,我们可以理解为WordCount程序,利用WordCount的思想, 在

2、Reduce 阶段对“苏”车牌不进行输出即可。对于套牌车辆的识别,Map阶段与WordCount是一样的,在Reduce阶段我们将统计 相同车牌出现的情况。我们将编写两个类,一个类用于加载C+的so动态库,另一个完成MapReduce算 法。SelectPic.javaimport java.io.File;import java.util.Vector;public class SelectPic private Vector pics = null;public SelectPic() pics = new Vector();static System.loadLibrary(Easype

3、r);public native String getPlate(String inPath);public void doPicNames(String inPath) File file = new File(inPath);File listFiles = file.listFiles();for (File files : listFiles) if (!files.isDirectory() String name = files.getName();String plate = getPlate(inPath + / + name); if (plate.length() 3)pl

4、ate.substring(3);public static void main(String args) SelectPic sp = new SelectPic(); sp.doPicNames(image);PlateRecog.javaimport java.io.IOException;import java.util.Vector;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.

5、apache.hadoop.io.IntWritable;import org.apache.hadoop.io.LongWritable;import org.apache.hadoop.io.NullWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.io.WritableComparable;import org.apache.hadoop.io.WritableComparator;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoo

6、p.mapreduce.Mapper;import org.apache.hadoop.mapreduce.Reducer;import org.apache.hadoop.mapreduce.lib.input.FilelnputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import org.apache.hadoop.util.GenericOptionsParser;public class PlateRecog public static class PlateRecogMapper_co

7、ll extends Mapper private SelectPic sp = null;private FileSystem HDFS = null;Overrideprotected void setup(Mapper.Context context)throws IOException, InterruptedException Configuration conf = context.getConfiguration();sp = new SelectPic();HDFS = FileSystem.get(conf);Overrideprotected void map(LongWr

8、itable key, Text value, Mapper.Context context)throws IOException, InterruptedException String splits = value.toString().split();String ds = splitsO.substring(O, splitsO.length() - 4) + _t.jpg;Path src = new Path(splits0);Path dst = new Path(ds);HDFS.copyToLocalFile(src, dst);String plate = sp.getPl

9、ate(ds);plate = plate.substring(3);context.write(new Text(plate.substring(0, 1), new IntWritable(l);/统计非江苏的车牌的数量public static class PlateRecogReducer_coll extends Reducer Overrideprotected void reduce(Text k2, Iterable v2s,Reducer.Context context)throws IOException, InterruptedException if (!k2.toSt

10、ring().equals(苏)int sum = 0;for (IntWritable v2 : v2s) sum += v2.get();context.write(new Text(k2.toString() + 车牌的数量:),new IntWritable(sum);public static class PlateRecogMapper_find extends Mapper private SelectPic sp = null;private FileSystem HDFS = null;Overrideprotected void setup(Mapper.Context c

11、ontext)throws IOException, InterruptedException Configuration conf = context.getConfiguration();sp = new SelectPic();HDFS = FileSystem.get(conf);Overrideprotected void map(LongWritable key, Text value, Mapper.Context context)throws IOException, InterruptedException String splits = value.toString().s

12、plit();String ds = splits0.substring(0, splitsO.length() - 4) + _t.jpg;Path src = new Path(splits0);Path dst = new Path(ds);HDFS.copyToLocalFile(src, dst);String plate = sp.getPlate(ds);plate = plate.substring(3);String plateInfo = plate + _ + splits1;/ 皖 A12345_l 45context.write(new Text(plateInfo)

13、, new Text(dst.getName().substring(O, dst.getName().length()-public static class PlateRecogReducer_find extends Reducer private Vector samePlates = null;Overrideprotected void setup(Reducer.Context context)throws IOException, InterruptedException samePlates = new Vector();Overrideprotected void redu

14、ce(Text k2, Iterable v2s, Reducer.Context context)throws IOException, InterruptedException int sum = 0;String splits = k2.toString().split(_);samePlates.clear();for (Text v2 : v2s) +sum;samePlates.add(v2.toString();if (sum 1) String sameplate =;for (int i = 0; i $x:/usr/cstor/hadoop/lib;done;37.3.3

15、打包提交然后使用Eclipse开发工具将该代码打包,选择主类为PlateRecog。假定打包后的文 件名为PlateRecog.jar,主类PlateRecog位于默认包下,则可使用如下命令向Hadoop集群 提交本应用。rootclient hadoop# bin/hadoop jar PlateRecog.jar -files ./plate/use/libEasyper.so,./plate/use/etc/,./plate/use/resources/ /user/mapreduce/platerecog/in/plate.txt /user/mapreduce/platerecog/

16、count/ /user/mapreduce/platerecog/samePlate/其中“hadoop”为命令,“jar”为命令参数,后面紧跟打的包,“-files”是附加文件指 令,“./pla te/use/libEasyper.so,./pla te/use/e tc/,./pl 是同时提交到0 集群上的配 置文件和动态库。“/user/mapreduce/platerecog/in/plate.txt”为输入文件在HDFS中的位置, “/user/mapreduce/platerecog/count/ 和 “/user/mapreduce/platerecog/samePlate/

17、”为输出文 件在HDFS中的位置,分别对应的是统计车牌的数量的输出文件count,套牌车识别的结 果文件 samePlate。37.4 实验结果37.4.1 输入数据输入数据格式如下:plate.txt (空格()分割)(数据放在/root/data/37/in目录下)/user/mapreduce/platerecog/images/99.jpg 2/user/mapreduce/platerecog/images/100.jpg 2/user/mapreduce/platerecog/images/101.jpg 2/user/mapreduce/platerecog/images/102

18、.jpg 2/user/mapreduce/platerecog/images/103.jpg 2/user/mapreduce/platerecog/images/104.jpg 2/user/mapreduce/platerecog/images/105.jpg 2/user/mapreduce/platerecog/images/106.jpg 2/user/mapreduce/platerecog/images/107.jpg 237.4.2 执行结果在 client 上执行对 HDFS 上的文件/user/mapreduce/platerecog/count/part-r-00000

19、 内容查 看的操作,查看外省车辆的统计情况rootclient hadoop# bin/hadoop fs -cat /user/mapreduce/platerecog/count/p*屏幕上显示如图37-1所示。root(aclient hadoop# bin/hadoop fs -cat /user/mapreduce/platerecog/count/p* 16/12/15 01:03:16 WARN util.NativeCodeLoader: Unable to load native-hadoop library e applicable京车牌的数量:2冀车牌的数量:1吉车牌的数

20、量:2川车牌的数量:3晋车牌的数量:4沪车牌的数量:2津车牌的数量:5浙车牌的数量:21渝车牌的数量:1湘车牌的数量:1甘车牌的数量:1皖车牌的数量:17粤车牌的数量:1蒙车牌的数量:1豫车牌的数量:1鄂车牌的数量:3青车牌的数量:1鲁车牌的数量:2图 37-1在 client 上执行对 HDFS 上的文件/user/mapreduce/platerecog/samePlate/part-r-00000 内 容查看的操作,查看两处监控的套牌车辆的情况。rootclient hadoop# bin/hadoop fs -cat /user/mapreduce/platerecog/samePlate/p*屏幕上显示如图37-2所示。root(aclient hadoop# bin/hadoop fs -cat /user/map reduce/plat erecog/samePlate/p* 16/12/15 01:03:26 WARN util.NativeCodeLoader: Unable to load native-hadoop library e applicable存在套牌的车辆的车牌号为:浙F2Q001车牌编号为:51和118图 37-2我们将两个编号的车牌图片拿出来查看一下,如图37-3所示。图 37-3

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!