Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

android - 使用openCV从照片中检测QR码(QR code detection issue from photo using openCV)

I am currently working on an android application, that should be able to detect a QR code from a picture taken.

(我目前正在开发一个android应用程序,该应用程序应该能够从拍摄的照片中检测QR码。)

It is not necessary to decode the QR code because it's only needed to calibrate the camera.

(无需解码QR码,因为只需要校准摄像机即可。)

I am using openCV and when I tried to detect the QR code from the original downloaded picture of the QR code it works fine.

(我正在使用openCV,当我尝试从QR码的原始下载图片中检测QR码时,它工作正常。)

That's the code I used:

(那是我使用的代码:)

bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.qrcodemitzeugs);
Mat img =new Mat();
Utils.bitmapToMat(bitmap,img)
Mat points= new Mat();
QRCodeDetector detector=new QRCodeDetector();
boolean data = detector.detect(img, points);

But when I try the same Code on a photo taken with my smartphone's camera, the QR code doesn't get detected.

(但是,当我在用智能手机的相机拍摄的照片上尝试相同的Code时,则不会检测到QR Code。)

I searched for a solution and found that maybe the contrast wasn't high enough so converted the picture into binary using following code:

(我搜索了一个解决方案,发现对比度可能不够高,因此请使用以下代码将图片转换为二进制图像:)

Imgproc.cvtColor(img,img2,Imgproc.COLOR_BGR2GRAY);
Imgproc.threshold(img2,img2,100,255,Imgproc.THRESH_BINARY);

It returned the whole image in black and white but still the QR code wasn't detected.

(它以黑白方式返回了整个图像,但仍未检测到QR码。)

Did I do something wrong or is there a solution for this problem?

(我做错了什么还是有解决此问题的方法?)

  ask by VerzweifelterStudent97 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...