# 百度图像识别车牌系统 **Repository Path**: BHWxiaoqiang/iMX6ULL ## Basic Information - **Project Name**: 百度图像识别车牌系统 - **Description**: 学习Linux,基于野火IMX6ULL开发板,使用了Qt以及交叉编译等。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2024-09-02 - **Last Updated**: 2025-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Imx6ULL项目 > 基于百度图像的一个小作品: > 此项目参考讯为的图像识别项目教程: [https://www.bilibili.com/video/BV157411c7sc/](https://www.bilibili.com/video/BV157411c7sc/) ## 制作总结 > 我买的摄像头版本是:野火 OV5640 摄像头模块。开发板版本:野火的iMX6ULL开发板 1. linux板环境准备 > QT交叉编译环境的搭建 > > 我安装的是 arm-linux-gnueabihf-gcc v8.3.0 交叉编译器。 2. 百度应用的创建与准备 接下来是百度端的应用创建 ![输入图片说明](%E7%99%BE%E5%BA%A6%E4%BA%91.png) ``` 主要是用到百度的三元组 AppID API Key Secret Key ``` 3. 依赖库的交叉编译 ``` 接下来其他的就暂时脱离QT了,这是对 整个图像识别和百度语音识别做准备的: 编译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 编译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 编译jsoncpp (我这里虽然编译成功了,但是在QT里总是调用失败,解决方法见下文) 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 ``` 4. 根文件系统的整理与拷贝 ``` 然后就是以上依赖库的环境变量引导,把上面的文件在PC上放到指定位置进行交叉编译生成QT可执行文件,nfs扔到板子上运行,会提示找不到依赖库。 此时把依赖库文件,放到imx6ull板子的指定路径,并且编辑环境变量。再次运行就不报错了。 vi ./etc/init.d/rcS 讯为的教程使用的是 设计根文件系统,而我是直接NFS传进去,其实原理是一样的,无论怎么样,只要能让QT应用在板子的指定位置找到指定的依赖文件即可。 ``` 5. QTAPP的编写 百度APP初始化部分: ``` #include "json/include/json/json.h" //由于我没编译成功jsoncpp的依赖库,所以用这种本地依赖的方法来作 #include "ocr.h" #include "speech.h" // 设置语音合成 APPID/AK/SK std::string speech_app_id = "你的 App ID"; std::string speech_api_key = "你的 Api key"; std::string speech_secret_key = "你的 Secret Key"; aip::Speech client_speech(speech_app_id, speech_api_key, speech_secret_key); // 设置文字识别APPID/AK/SK std::string app_id = "你的 App ID"; std::string api_key = "你的 Api key"; std::string secret_key = "你的 Secret Key"; aip::Ocr client(app_id, api_key, secret_key); ``` 车牌识别部分: ``` 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 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"); } } ``` 语音合成(文字转语音部分): ``` int tts(std::string text,std::string FileName) { std::ofstream ofile; std::string file_ret; std::map options; options["spd"] = "4"; options["per"] = "5"; // 合成成功的二进制数据写入文件中 ofile.open(FileName, std::ios::out | std::ios::binary); // 不带可选参数调用 //Json::Value result = client_speech.text2audio("百度语音合成测试", aip::null, file_ret); // 带可选参数调用, 参数参考参数列表中的可选参数 Json::Value result = client_speech.text2audio(text, options, file_ret); // 如果file_ret为不为空则说明合成成功,返回mp3文件内容回结果 if (!file_ret.empty()) { ofile << file_ret; return 0; } else { // 服务端合成错误 std::cout << result.toStyledString(); return 1; } return 2; } ``` 拍照按钮事件的执行: ``` 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()); //语音合成 sp_out = tts(out,"./a.mp3"); if(sp_out == 0) { //播放 开启新线程执行系统命令 QProcess *process = new QProcess(); process->start("gplay-1.0 a.mp3"); // system("gplay-1.0 a.mp3"); }else { ui->statusbar->showMessage("语音合成失败"); } QMessageBox::warning(this, tr("OK"), out.c_str()); // Display captured image for 4 seconds. 这里会在linux板子上面卡住 // displayCapturedImage(); // QTimer::singleShot(4000, this, &Camera::displayViewfinder); } ```