<项目> 基于Imx6ull的车牌识别项目
前言
这个项目是自己用来练手学linux的项目,跟着讯为电子出的教程做的一个车牌识别项目。
硬件用的野火的开发板+野火的五寸触摸屏+免驱的摄像头,系统用的野火的debian系统,上位机是用Qt写的。
Drawn By:67373UPUP
在百度Ai创建一个车牌识别的应用
我们需要 AppID , API Key , Secret Key这三组数据,在后面写Qt上位机会用到。
在Ubuntu下配置环境
1.1:编译openssl
cd openssl-1.0.2f/
setarch i386 ./config no-asm shared --prefix=/usr/local/openssl/
CC= arm-linux-gnueabihf-gcc
AR= arm-linux-gnueabihf-ar $(ARFLAGS) r
RANLIB= arm-linux-gnueabihf-ranlib
NM= arm-linux-gnueabihf-nm
make
sudo make install
1.2:编译curl
./configure --prefix=/usr/local/curl/ --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ --with-ssl=/usr/local/openssl
make
sudo make install
1.3:编译jsoncpp
mkdir arm_jsoncpp
cp -r include/ arm_jsoncpp/
cp src/lib_json/* arm_jsoncpp/
arm-linux-gnueabihf-g++ -c *.cpp -I./include -fPIC
mkdir lib
ar cr ./lib/libjsoncpp.a *.o
编译动态库
arm-linux-gnueabihf-g++ -shared -fPIC *.cpp -I./include -o ./lib/libjsoncpp.so
经测试jsoncpp的动态库在qt里面用不成,可以直接将库放在开发板内,然后直接用qt引用就行了。
参考资料:https://www.cnblogs.com/zengjfgit/p/4959965.html
将编译好的库拷贝到开发板
root@npi:/mnt# cp -r curl /usr/local/
root@npi:/mnt# cp -r openssl /usr/local/
root@npi:/mnt# cp -r curl/lib/* /lib/
root@npi:/mnt# cp -r openssl/lib/* /lib/
配置开发板的环境变量并更新
打开并编辑bashrc
vi .bashrc
在文末添加如下内容
export PATH=$PATH:/usr/local/openssl/bin
export PATH=$PATH:/usr/local/curl/bin
编辑完成以后 更新一下,然后查看是否OK
source ~/.bashrc
echo $PATH
Qt编写
1.1:添加json静态库头文件 和 openssl,curl动态头文件以及百度Ai的库文件
HEADERS = \
base/base.h \
base/base64.h \
base/http.h \
base/utils.h \
camera.h \
imagesettings.h \
json/assertions.h \
json/autolink.h \
json/config.h \
json/features.h \
json/forwards.h \
json/json.h \
json/reader.h \
json/value.h \
json/version.h \
json/writer.h \
ocr.h \
videosettings.h
INCLUDEPATH += /usr/local/curl/include \
/usr/local/openssl/include \
LIBS += /usr/local/curl/lib/libcurl.so.4.5.0 \
/usr/local/openssl/lib/libssl.so.1.0.0 \
/usr/local/openssl/lib/libcrypto.so.1.0.0 \
1.1:设置文字识别APPID/AK/SK
// 设置文字识别APPID/AK/SK
std::string app_id = "22235833";
std::string api_key = "nKj7kPg8USsPL0Okt5VwqKUt";
std::string secret_key = "DFYGup6LjX6T9ejWbQPyt0gOjcf9oD54";
aip::Ocr client(app_id, api_key, secret_key);
1.1:车牌识别函数
//车牌识别函数
std::string GetPlateNumber(std::string PicturePath)
{
Json::Value result;
std::string image;
aip::get_file_content(PicturePath.c_str(), &image);
// 调用车牌识别
result = client.license_plate(image, aip::null);
// 如果有可选参数
std::map<std::string, std::string> options;
options["multi_detect"] = "true";
// 带参数调用车牌识别
result = client.license_plate(image, options);
if(result["error_code"].isNull()) //无报错
{
return (result["words_result"][0]["number"].asString());
}else
{
return ("error");
}
}
1.1:拍照事件+执行调用百度AI
//拍照事件+执行调用百度AI
void Camera::processCapturedImage(int requestId, const QImage& img)
{
Q_UNUSED(requestId);
QImage scaledImage = img.scaled(ui->viewfinder->size(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation);
ui->lastImagePreviewLabel->setPixmap(QPixmap::fromImage(scaledImage));
const QPixmap *pixmap=ui->lastImagePreviewLabel->pixmap();
pixmap->save("./a.jpg"); //存储到指定位置
std::string out;
//std::int8_t sp_out;
out = GetPlateNumber("./a.jpg");
ui->statusbar->showMessage(out.c_str());
QMessageBox::warning(this, tr("OK"), out.c_str());
// Display captured image for 4 seconds.
//displayCapturedImage();
//QTimer::singleShot(4000, this, &Camera::displayViewfinder);
}
效果展示
参考资料
讯为电子教程视频
json添加静态库
阿正的博客
json,curl,openssl库& 百度API api_cpp & Qt源码:https://gitee.com/linggan17/camera.git