admin 管理员组文章数量: 1086019
2024年4月16日发(作者:什么是c语言预先声明的单词)
detectanddecode 使用方法
`detectAndDecode`是OpenCV中的一个函数,用于检测和解析二维码。其用法可以参考
如下代码:
- C++:
```cpp
#include " pch.h"
#include < iostream>
#include < opencv2/>
#include < iostream>
using namespace cv;
using namespace std;
/**
* @brief 用于显示检测到的 QR 码周围的框
*
* @param im
* @param bbox
*/
void display(Mat &im, Mat &bbox) {
int n = ;
for (int i = 0; i < n; i++) {
line(im, Point2i(< float> (i,0), < float> (i, 1)),
Point2i(< float> ((i + 1) % n, 0), < float> ((i + 1) % n, 1)), Scalar(255,
0, 0), 3);
}
imshow(" Result", im);
}
int main() {
// Read image
Mat inputImage = imread("./image/");
// QR detector
QRCodeDetector qrDecoder = QRCodeDetector::QRCodeDetector();
// QR code bounding box coordinates, extracted QR code
Mat bbox, rectifiedImage;
// Detect QR code
std::string data = AndDecode(inputImage,
rectifiedImage);
// Get QR code data link
if (() > 0) {
cout << " Decoded Data : " << data << endl;
display(inputImage, bbox);
tTo(rectifiedImage, CV_8UC3);
// Show the QR code
imshow(" Rectified QRCode", rectifiedImage);
waitKey(0);
}
else {
cout << " QR Code not detected" << endl;
}
return 0;
}
```
- Python:
```python
import cv2
import numpy as np
import time
inputImage = ("./image/")
def display(im, bbox):
bbox,
n = len(bbox)
for j in range(n):
(im, tuple(bbox[j](0)), tuple(bbox((j+1) % n)(0)),(255,0,0),
3)
# Display results
("Results", im)
qrDecoder = Detector()
t = ()
data,bbox,rectifiedImage = AndDecode(inputImage)
print("Time Taken for Detect and Decode : {:.3f} seconds".format(()
- t))
if len(data)>0:
print("Decoded Data : {}".format(data))
display(inputImage, bbox)
rectifiedImage = 8(rectifiedImage)
("Rectified QRCode", rectifiedImage)
else:
print("QR Code not detected")
("Results", inputImage)
e("",inputImage)
y(0)
yAllWindows()
```
在上述代码中,通过`detectAndDecode`函数对二维码图像进行检测和解码,返回从二
维码解码的数据、找到的二维码四边形的顶点数组以及包含经过整流和二值化二维码的输出
图像。
版权声明:本文标题:detectanddecode 使用方法 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1713256166a626226.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论