如何使用C++;Linux上的opencv库? 我用OpenCV C++库来对QRCODEL进行解码,这里给出了来自这个网站的样本测试代码:
当我编译此测试程序时,出现以下错误:如何使用C++;Linux上的opencv库? 我用OpenCV C++库来对QRCODEL进行解码,这里给出了来自这个网站的样本测试代码:,c++,linux,opencv,qr-code,C++,Linux,Opencv,Qr Code,当我编译此测试程序时,出现以下错误: 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’
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`
test.cc:
//https://www.learnopencv.com/opencv-qr-code-scanner-c-and-python/
#包括
#包括
#包括
#包括
#包括
使用名称空间cv;
使用名称空间std;
无效显示(Mat&im、Mat&bbox)
{
int n=bbox.rows;
对于(int i=0;i0)
{
cout首先,代码与OpenCV 4.0兼容,因此请确保您使用的是OpenCV 4.0。如果您使用的是OpenCV 4.0,您可能在eclipse中引用了不同版本的OpenCV路径
对于解决方案,有两个步骤
步骤1
在终端中,键入pkg config--cflags opencv4.Output将类似于I/usr/local/include/opencv4/opencv.Copy Output并将其粘贴到第一个链接中所示的位置
步骤2
再次从终端输入pkg config--libs opencv4。输出类似于L/usr/local/lib。复制输出并将其粘贴到第二个链接中显示的位置。然后添加标题引用到库(-L)部分,如链接中所示
这些步骤将解决您的问题。首先,代码与OpenCV 4.0兼容,因此请确保您使用的是OpenCV 4.0。如果您使用的是OpenCV 4.0,您可能在eclipse中引用了不同版本的OpenCV path
对于解决方案,有两个步骤
步骤1
在终端中,键入pkg config--cflags opencv4.Output将类似于I/usr/local/include/opencv4/opencv.Copy Output并将其粘贴到第一个链接中所示的位置
步骤2
再次从终端输入pkg config--libs opencv4。输出类似于L/usr/local/lib。复制输出并将其粘贴到第二个链接中显示的位置。然后添加标题引用到库(-L)部分,如链接中所示
这些步骤将解决您的问题。看起来您只需要包含QRCodeDetector
的头文件。您使用的是OpenCV 4.0吗?正如本网站显示的那样,QRCodeDetector是我包含的头文件的一部分。是的,但在您的安装中,如果您查看头文件,它实际上是否定义了QRCodeDetector
?您检查了吗?没有。您链接到的示例引用了OpenCV版本4.0。错误是QRCodeDetector
未定义。我要求您做的只是检查应该定义它的头文件(如果它们与您链接到的示例版本相同)确实要定义它。这很难吗?如果他们不定义QRCodeDetector
,那么您将得到一个编译错误。头文件是否定义QRCodeDetector
?好吧,那么您没有使用与示例相同版本的opencv:这就是它无法编译的原因。解决这一问题取决于您。看起来您只需要输入包含QRCodeDetector
的头文件。您是否使用OpenCV 4.0?因为本网站显示QRCodeDetector是我包含的头文件的一部分。是的,但在您的安装中,如果您查看该头文件,它实际上是否定义了QRCodeDetector
?您检查过了吗?不,我没有。您链接的示例指的是OpenCV版本4.0。错误是说未定义QRCodeDetector
。我要求您做的只是检查应该定义它的头文件(如果它们与您链接到的示例版本相同)确实要定义它。这很难吗?如果他们不定义QRCodeDetector
,那么您将得到一个编译错误。头文件是否定义了QRCodeDetector
?好吧,那么您没有使用与示例相同版本的opencv:这就是它无法编译的原因。解决这一问题取决于您。