-
实验三十七
综合实战:车牌识别
37.1
实验目的
基于
MapReduce
思想,编写车牌识别程序。实现对江苏
某两处监控图片中的车牌的
识别,完成对除江苏省车辆外的外省车辆的统计,并完成对两
处监控中套牌车辆的识别,
并得出结果。
37.2
实验要求
要能理解
< br>MapReduce
编程思想,会编写
MapReduc
e
车牌识别程序,能够利用
Java
调
用已封装好
C++
的
< br>so
动态库完成车牌的识别,然后利用
MapReduc
e
完成对车牌的统计和
对套牌车的识别。最后将其执行并分析执
行过程。
37.3
实验步骤
37.3.1
编写程序
对于外省车牌的统计,我们可以理解为
WordCount
程序
,利用
WordCount
的思想,
在
Reduce
阶段对
“
苏
”
车牌不进行输出即可。
对于套牌车辆的识别,
Map
阶段与<
/p>
WordCount
是一样的,在
Red
uce
阶段我们将统计
相同车牌出现的情况。
< br>
我们将编写两个类,一个类用于加载
C++
的
so
动态库,另一个完成
MapReduce
算
法。
import
import
;
public class SelectPic {
private Vector
public SelectPic() {
}
pics = new Vector<>();
实验手册
static {
}
public native String
getPlate(String inPath);
public void doPicNames(String inPath) {
}
public static void
main(String[] args) {
}
}
SelectPic sp = new SelectPic();
ames(
File file = new
File(inPath);
File[] listFiles = les();
for (File files : listFiles) {
}
if
(!ctory()) {
}
String name =
e();
String plate = getPlate(inPath +
if (() > 3)
ing(3);
brary(
import ption;
import
import uration;
import stem;
import
import table;
import itable;
import itable;
import
import leComparable;
import
leComparator;
import
import
208
实验手册
import r;
import putFormat;
import tputFormat;
import
cOptionsParser;
public
class PlateRecog {
public
static class PlateRecogMapper_coll extends
Mapper
}
//
统计非江苏的车牌的数量
public static class PlateRecogReducer_coll extends
Reducer
@Override
protected void
reduce(Text k2, Iterable
Reducer
@Override
protected void
map(LongWritable key, Text value,
Mapper
}
throws
IOException, InterruptedException {
@Override
protected void
setup(Mapper
}
throws IOException,
InterruptedException {
Configuration
conf = figuration();
sp = new
SelectPic();
HDFS = (conf);
private SelectPic sp = null;
private FileSystem HDFS = null;
IntWritable>.Context context)
String[] splits =
ng().split(
String ds =
splits[0].substring(0, splits[0].length() - 4) +
Path src = new Path(splits[0]);
Path dst = new Path(ds);
LocalFile(src, dst);
String
plate = te(ds);
plate = ing(3);
(new Text(ing(0, 1)), new
IntWritable(1));
207
实验手册
}
public
static class PlateRecogMapper_find extends
Mapper
context)
6)));
//
皖
A12345_1 45
(new Text(plateInfo), new
Text(e().substring(0, e().length() -
throws IOException,
InterruptedException {
String[] splits
= ng().split(
String ds =
splits[0].substring(0, splits[0].length() - 4) +
Path src = new Path(splits[0]);
Path dst = new Path(ds);
LocalFile(src, dst);
String
plate = te(ds);
plate = ing(3);
String plateInfo = plate + '_' +
splits[1];
@Override
protected void map(LongWritable key,
Text value, Mapper
@Override
protected void
setup(Mapper
}
throws IOException,
InterruptedException {
Configuration
conf = figuration();
sp = new
SelectPic();
HDFS = (conf);
private SelectPic sp = null;
private FileSystem HDFS = null;
}
}
throws IOException,
InterruptedException {
int sum = 0;
for (IntWritable v2 : v2s) {
}
(new Text(ng()
+
车牌的数量:
sum +=
();
if (!ng().equals(
苏
208
实验手册
}
public
static class PlateRecogReducer_find extends
Reducer
context)
}
public static class
findGroupComparator extends WritableComparator {
protected findGroupComparator() {
super(, true);//
注册
comparator
}
throws IOException,
InterruptedException {
int sum = 0;
String[] splits =
ng().split(
();
for (Text v2
: v2s) {
}
if (sum > 1) {
}
String sameplate =
for (int i = 0; i < () - 1; ++i) {
}
sameplate +=
(() - 1);
(new
Text(
存在套牌的车辆的车牌号为
:
车牌编号为:
sameplate += (i) +
和
++sum;
(ng());
@Override
protected void
reduce(Text k2, Iterable
@Override
protected void
setup(Reducer
}
throws IOException,
InterruptedException {
samePlates = new
Vector<>();
private Vector
}
207