opencv4.0.0图像处理:二维码扫描器java版(五)

浏览到某英文网页上提供了基于opencv的C++和python版的二维码扫描器,其链接为https://www.learnopencv.com/opencv-qr-code-scanner-c-and-python/,不过貌似没有java版的,未免遗憾

这里本人依样画葫芦,仿造了java版本的二维码扫描器,方为完备

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
   public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

Mat image = imread("images/qrcode-feature.jpg");
QRCodeDetector detector = new QRCodeDetector();
Mat points = new Mat();
Mat straight_qrcode = new Mat();
String data = detector.detectAndDecode(image, points, straight_qrcode);

if (data.length() > 0) {
System.out.println("Decoded Data :" + data);

display(image, points);

// HighGui.imshow("points", points);
straight_qrcode.convertTo(straight_qrcode, CvType.CV_8UC3);

HighGui.imshow("Rectified QRCode", straight_qrcode);

HighGui.waitKey(0);
}

System.exit(0);
}

public static void display(Mat image, Mat points) {
int n = points.rows();
for (int i = 0; i < n; i++) {
Imgproc.line(image, new Point(points.get(i, 0)), new Point(points.get((i + 1) % n, 0)),
new Scalar(255, 0, 0), 3);
}
HighGui.imshow("Result", image);
}

测试输出

Decoded Data :http://LearnOpenCV.com

二维码定位:

坚持原创技术分享,您的支持是我前进的动力!