如何在 Linux 上使用 opencv 库解码 QRCODE C++
How to decode QRCODE using C++ opencv library on Linux?
我正在使用opencv c ++库来解码Qrcode.在这里我给出了来自本网站的示例测试代码:https://www.learnopencv.com/opencv-qr-code-scanner-c-and-python/
当我编译这个测试程序时,我收到以下错误:
test.cc: In function ‘int main(int, char**)’:
test.cc:29:3: error: ‘QRCodeDetector’ was not declared in this scope
QRCodeDetector qrDecoder = QRCodeDetector::QRCodeDetector();
^~~~~~~~~~~~~~
test.cc:33:22: error: ‘qrDecoder’ was not declared in this scope
std::string data = qrDecoder.detectAndDecode(inputImage, bbox, rectifiedImage)
如何解决此错误?
test.cc:
//https://www.learnopencv.com/opencv-qr-code-scanner-c-and-python/
#include <opencv2/objdetect.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
void display(Mat &im, Mat &bbox)
{
int n = bbox.rows;
for(int i = 0 ; i < n ; i++)
{
line(im, Point2i(bbox.at<float>(i,0),bbox.at<float>(i,1)), Point2i(bbox.at<float>((i+1) % n,0), bbox.at<float>((i+1) % n,1)), Scalar(255,0,0), 3);
}
imshow("Result", im);
}
int main(int argc, char* argv[])
{
// Read image
Mat inputImage;
inputImage = imread(argv[1]);
QRCodeDetector qrDecoder = QRCodeDetector::QRCodeDetector();
Mat bbox, rectifiedImage;
std::string data = qrDecoder.detectAndDecode(inputImage, bbox, rectifiedImage);
if(data.length()>0)
{
cout << "Decoded Data : " << data << endl;
display(inputImage, bbox);
rectifiedImage.convertTo(rectifiedImage, CV_8UC3);
imshow("Rectified QRCode", rectifiedImage);
waitKey(0);
}
else
cout << "QR Code not detected" << endl;
}
//compile
g++ test.cc -o test `pkg-config opencv --cflags --libs`
首先,代码与OpenCV 4.0兼容,因此请确保您使用的是OpenCV 4.0。如果您使用的是 OpenCV 4.0,您可能在 eclipse 中引用了不同版本的 OpenCV 路径。
对于解决方案,有两个步骤。
步骤1
在终端中,键入 pkg-config --cflags opencv4。输出将类似于 I/usr/local/include/opencv4/opencv。复制输出并将其粘贴到第一个链接中显示的位置。
https://drive.google.com/open?id=1WSBEOaSF6JJvOiUSI_kop8wnRaK8TOIt
步骤2
再次从终端,键入 pkg-config --libs opencv4。输出将类似于 L/usr/local/lib。复制输出并将其粘贴到第二个链接中显示的位置。比添加标题引用到库(-l(部分,如链接所示。
https://drive.google.com/open?id=1VYJHNV10P8oj_pwaUh3GZJwWu8vDmUxA
此步骤将解决您的问题。
下面的引用线程(相同的问题,但包含所有详细信息(:https://forum.opencv.org/t/quirc-error-in-opencv-4/6804/3在 Ubuntu 22.04.1 上
在 Linux OpenCV4.* 构建中检测第三方库的存在。要使其使用捆绑的 QUIRC 使用(用于 cmake(:-DBUILD_QUIRC=ON -DQUIRC=ON
完整命令如下所示:
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local/OpenCV47
-D INSTALL_C_EXAMPLES=ON
-D WITH_TBB=ON
-D WITH_V4L=ON
-D WITH_OPENGL=ON
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules
-D BUILD_EXAMPLES=ON
-DBUILD_QUIRC=ON -DQUIRC=ON
..
上面的命令对我有用;可以调整其他选项以满足您的需求。
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 如何使用 OpenCV 解码在两个 UWP 应用之间发送的图像字节?
- 将帧从 h264 流解码到 OpenCV Mat
- OpenCV 检查计算机上是否安装了视频编解码器 (C++)
- OpenCV:FFMPEG:编解码器 ID 12 和格式 'mp4 / MP4 不支持标记
- 如何将 Openh264 解码帧无延迟输出格式转换为 OpenCV 矩阵
- 如何在 Linux 上使用 opencv 库解码 QRCODE C++
- OPENCV解码灰色代码模式相机校准错误.如何格式化固有和外在结果
- OpenCV是在没有CUDA视频解码支持的情况下建造的
- 如何为 OpenCV 的视频编写器动态选择可用的编解码器?
- OpenCV videoWriter编解码器问题
- openCV 2.4.10丢失了cinepak radius编解码器
- 解码音频和视频并处理这两个流——ffmpeg、sdl、opencv
- 视频编解码器的H264与opencv
- Opencv编解码器选择对话框未显示
- 从blob SQLite读取二进制图像并使用OpenCV imdecode解码的最佳方法是什么?