light-LPR
Light-LPR是一个瞄准可以在嵌入式设备、手机端和普通的x86平台上运行的车牌识别开源项目,旨在支持开放场景的车牌识别, 支持目前国内所有的车牌识别。项目源码
light-LPR的下载
#安装opencv4.0及以上
#安装cmake3.0以上版本
git clone https://github.com/lqian/light-LPR
有源码测试
测试代码
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <assert.h>
#include "mlpdr/MLPDR.h"
using namespace std;
using namespace mlpdr;
using namespace cv;
int main(int argc, char ** argv) {
MLPDR detector("../models/", 0.9f, 0.7f, 0.7f);
Mat img = imread(argv[1],1);
assert(!img.empty());
TickMeter tm;
tm.start();
// std::vector<mlpdr::PlateInfo> plateInfos = detector.Detect(img, 40, 3); // 608.23 ms
vector<PlateInfo> plateInfos = detector.recognize(img);
tm.stop();
printf("detect cost: %f (ms)\n", tm.getTimeMilli());
for (auto pi: plateInfos) {
cout << "plateNo: " << pi.plateNo << endl;
}
}
配置
对于完整的项目,需要将编译器指定为 afl-clang,然后再进行编译。
export CC=afl-clang
export CXX=afl-clang++
mkdir build
cd build
cmake ../
make -j4
fuzz
正式执行 fuzz 测试的命令如下:
mkdir in
# 在in文件下下创建image语料库,使用jpeg.dict字典
# https://github.com/AFLplusplus/AFLplusplus/tree/stable/dictionaries
afl-fuzz -x dict/jpeg.dict -m none -i in -o out_res ./examples/demo @@
测试结果
黑盒测试
配置
首先在下载好 light-LPR 后,对 light-LPR 直接进行编译安装,生成二进制文件。
# 测试 ./examples/demo in/1.jpg
# make的时候会出现与opencv4的很多兼容问题,下面有解决方案。
cmake ../
make
启用QEMU模式,要先编译。
# 进入到AFLplusplus所在位置
cd qemu_mode
./build_qemu_support.sh
fuzz
afl-fuzz -Q -m none -i in -o out_res ./examples/demo -f
测试结果
在加了字典之后会出现第一个测试图片就crash的错误。
注意事项
-
CMake Error at CMakeLists.txt:23 (find_package): Could not find a configuration file for package “OpenCV” that is compatible with requested version “3.0.0”.
打开CMakeLists.txt文件,然后将opencv 3.0.0改为4.0.0,这样opencv4以上的版本就可以使用了。 -
CMake Error at src/examples/CMakeLists.txt:1 (find_package): Could not find a configuration file for package “OpenCV” that is compatible with requested version “3.4.0”.
解决办法同1. -
error: use of undeclared identifier ‘CV_BGR2RGBA’; cv::cvtColor(img, MatTemp, CV_BGR2RGBA, 4);
改为 cv::cvtColor(imageBGR, imageRGBA, cv::COLOR_BGR2BGRA) -
PROGRAM ABORT : Test case ‘id:000000,time:0,orig:1.jpg’ results in a timeout. Location : perform_dry_run(), src/afl-fuzz-init.c:593。
不是jpg格式,引起了程序的崩溃,使用afl++的字典即可。