# QR code detection

**URL:** <https://forum.opencv.org/t/qr-code-detection/7372>\
**Category:** Python\
**Created:** [February 1, 2022, 11:49am UTC](https://forum.opencv.org/t/qr-code-detection/7372 "2022-02-01T11:49:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattia](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@mattia](https://forum.opencv.org/u/mattia)\
**Post date:** [February 1, 2022, 11:49am UTC](https://forum.opencv.org/t/qr-code-detection/7372/1 "2022-02-01T11:49:40Z")

</div>

Hi, i’m newbie to OpenCV and i use a bit of python, i’m using OpenCV in Touchdesigner to build a qr code reader, i’m using this code:

```
img = op('null1').numpyArray(delayed=True)
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
gray = (gray*255).astype(np.uint8)

detector = cv2.QRCodeDetector()

data, bbox, straight_qrcode = detector.detectAndDecode(gray)

# if there is a QR code
if bbox is not None:
	#print(f"QRCode data:\n{data}")
	# display the image with lines
	# length of bounding box
	n_lines = len(bbox)
	for i in range(n_lines):
		# draw all lines
		point1 = tuple(bbox[i][0])
		point2 = tuple(bbox[(i+1) % n_lines][0])
		cv2.polylines(img, np.int32([bbox]), True, (255, 0, 0), 2)

scriptOp.copyNumpyArray(img)

```

And this works fine, in fact i can see that the qr code is recognized, but i cannot read the data of the qr code, i supposed that print(data) should give me that but i get empty string.

Thanks

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [February 1, 2022, 11:59am UTC](https://forum.opencv.org/t/qr-code-detection/7372/2 "2022-02-01T11:59:20Z")

</div>

> [@mattia](#):
>
> `gray `

exactly that picture please, to reproduce the issue. dump it as png (`imwrite`) and post it here.

---

<div class="post-metadata">

**Author:** ![mattia](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@mattia](https://forum.opencv.org/u/mattia)\
**Post date:** [February 1, 2022, 12:06pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/3 "2022-02-01T12:06:30Z")

</div>

![null1](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/d/d3a3f7f23ba9fdae4052d36c7fd3af4e7af048ea.png)

Hi thanks for the repply, since i’m working with Python in Touchdeisgner i don’t have a single image on drive but i’m working on a texture live feed provide by a touchdesigner operator

img = op(‘null1’).numpyArray(delayed=True)

This operator function build in touchdesigner provide the texture feed to open cv, i have save a frame as .png of the video feed and uploaded

---

<div class="post-metadata">

**Author:** ![mattia](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@mattia](https://forum.opencv.org/u/mattia)\
**Post date:** [February 1, 2022, 12:15pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/4 "2022-02-01T12:15:37Z")

</div>

![qrcode](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/b/b14c0f3baf583329c20a6bf0f070648084224a30.png)  
This is the qr code

---

<div class="post-metadata">

**Author:** ![mattia](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@mattia](https://forum.opencv.org/u/mattia)\
**Post date:** [February 1, 2022, 12:34pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/5 "2022-02-01T12:34:15Z")

</div>

Could depend on string format output of open CV, becouse i read on open cv wiki:  
Returns UTF8-encoded output string or empty string if the code cannot be decoded.

Maybe touchdesigner could not read UTF8 encoded string and this needed to be translated in different encoding method?

---

<div class="post-metadata">

**Author:** ![sturkmen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sturkmen/32/13_2.png) [@sturkmen](https://forum.opencv.org/u/sturkmen)\
**Post date:** [February 1, 2022, 1:41pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/6 "2022-02-01T13:41:02Z")

</div>

```auto
import numpy as np
import cv2 as cv

gray = cv.imread("d:/test/qr.png",cv.IMREAD_GRAYSCALE)
detector = cv.QRCodeDetector()
decode_info, points, _ = detector.detectAndDecode(gray)
print('code:',decode_info, '\npoints:', points)
print(cv.getBuildInformation())

```

## output:

code: 5  
points: [[[362. 75.]  
[570.99036 75.]  
[573. 284.]  
[362. 284.]]]

General configuration for OpenCV 4.5.5-dev =====================================  
Version control: 4.5.5-26-g36a618ebc4-dirty  
.  
.  
.

---

<div class="post-metadata">

**Author:** ![mattia](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@mattia](https://forum.opencv.org/u/mattia)\
**Post date:** [February 1, 2022, 1:52pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/7 "2022-02-01T13:52:10Z")

</div>

I have points but not decode\_info 😤

python \>\>\>  
[[[113. 284.]  
[113. 75.00961]  
[322. 73.]  
[322. 284.]]]

def onCook(scriptOp):

```
img = op('null1').numpyArray(delayed=True)
gray = cv2.cvtColor(img, cv2.IMREAD_GRAYSCALE)
gray = (gray*255).astype(np.uint8)

detector = cv2.QRCodeDetector()

decode_info, points, _ = detector.detectAndDecode(gray)

print(decode_info, points)

scriptOp.copyNumpyArray(img)
```

---

<div class="post-metadata">

**Author:** ![sturkmen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sturkmen/32/13_2.png) [@sturkmen](https://forum.opencv.org/u/sturkmen)\
**Post date:** [February 1, 2022, 1:59pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/8 "2022-02-01T13:59:56Z")

</div>

> [@sturkmen](#):
>
> `print(cv.getBuildInformation())`

what is `print(cv.getBuildInformation())`

---

<div class="post-metadata">

**Author:** ![mattia](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@mattia](https://forum.opencv.org/u/mattia)\
**Post date:** [February 1, 2022, 2:06pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/9 "2022-02-01T14:06:04Z")

</div>

python \>\>\>  
code:  
points: [[[40. 249.]  
[40. 40.]  
[249. 40.]  
[249. 249.]]]

General configuration for OpenCV 4.5.1 =====================================  
Version control: 4.5.1-dirty

Extra modules:  
Location (extra): D:/devel/opencv\_contrib/modules  
Version control (extra): 4.5.1

Platform:  
Timestamp: 2021-02-04T22:31:53Z  
Host: Windows 10.0.19042 AMD64  
CMake: 3.19.0-rc3  
CMake generator: Ninja  
CMake build tool: D:/devel/ninja/ninja.exe  
MSVC: 1928  
Configuration: Release

CPU/HW features:  
Baseline: SSE SSE2 SSE3  
requested: SSE3  
Dispatched code generation: SSE4\_1 SSE4\_2 FP16 AVX AVX2 AVX512\_SKX  
requested: SSE4\_1 SSE4\_2 AVX FP16 AVX2 AVX512\_SKX  
SSE4\_1 (15 files): + SSSE3 SSE4\_1  
SSE4\_2 (1 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2  
FP16 (0 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 FP16 AVX  
AVX (4 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 AVX  
AVX2 (29 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 FP16 FMA3 AVX AVX2  
AVX512\_SKX (4 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 FP16 FMA3 AVX AVX2 AVX\_512F AVX512\_COMMON AVX512\_SKX

C/C++:  
Built as dynamic libs?: YES  
C++ standard: 11  
C++ Compiler: C:/MVS16/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe (ver 19.28.29336.0)  
C++ flags (Release): /DWIN32 /D\_WINDOWS /W4 /GR /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /FS /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MD /O2 /Ob2 /DNDEBUG  
C++ flags (Debug): /DWIN32 /D\_WINDOWS /W4 /GR /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /FS /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MDd /Zi /Ob0 /Od /RTC1  
C Compiler: C:/MVS16/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe  
C flags (Release): /DWIN32 /D\_WINDOWS /W3 /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /FS /MD /O2 /Ob2 /DNDEBUG  
C flags (Debug): /DWIN32 /D\_WINDOWS /W3 /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /FS /MDd /Zi /Ob0 /Od /RTC1  
Linker flags (Release): /machine:x64 /INCREMENTAL:NO  
Linker flags (Debug): /machine:x64 /debug /INCREMENTAL  
ccache: NO  
Precompiled headers: NO  
Extra dependencies: cudart.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cufft.lib -LIBPATH:“C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.2/lib/x64”  
3rdparty dependencies:

OpenCV modules:  
To be built: aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn\_objdetect dnn\_superres dpm face features2d flann fuzzy gapi hfs highgui img\_hash imgcodecs imgproc intensity\_transform line\_descriptor mcc ml objdetect optflow phase\_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured\_light superres surface\_matching text tracking video videoio videostab world xfeatures2d ximgproc xobjdetect xphoto  
Disabled: python\_tests  
Disabled by dependency: -  
Unavailable: alphamat cnn\_3dobj cvv freetype hdf java julia matlab ovis python2 python2 sfm ts viz  
Applications: apps  
Documentation: NO  
Non-free algorithms: NO

Windows RT support: NO

GUI:  
Win32 UI: YES  
VTK support: NO

Media I/O:  
ZLib: build (ver 1.2.11)  
JPEG: build-libjpeg-turbo (ver 2.0.6-62)  
WEBP: build (ver encoder: 0x020f)  
PNG: build (ver 1.6.37)  
TIFF: build (ver 42 - 4.0.10)  
JPEG 2000: build (ver 2.3.1)  
OpenEXR: build (ver 2.3.0)  
HDR: YES  
SUNRASTER: YES  
PXM: YES  
PFM: YES

Video I/O:  
DC1394: NO  
GStreamer: NO  
DirectShow: YES  
Media Foundation: YES  
DXVA: YES

Parallel framework: TBB (ver 2020.1 interface 11101)

Trace: YES (with Intel ITT)

Other third-party libraries:  
Intel IPP: 2020.0.0 Gold [2020.0.0]  
at: D:/devel/opencv/BuildRelease/3rdparty/ippicv/ippicv\_win/icv  
Intel IPP IW: sources (2020.0.0)  
at: D:/devel/opencv/BuildRelease/3rdparty/ippicv/ippicv\_win/iw  
Lapack: NO  
Eigen: NO  
Custom HAL: NO  
Protobuf: build (3.5.1)

NVIDIA CUDA: YES (ver 11.2, CUFFT CUBLAS)  
NVIDIA GPU arch: 50 60 70 80  
NVIDIA PTX archs: 35 80

OpenCL: YES (NVD3D11)  
Include path: D:/devel/opencv/3rdparty/include/opencl/1.2  
Link libraries: Dynamic load

Python 3:  
Interpreter: C:/Python37/python.exe (ver 3.7.9)  
Libraries: C:/Python37/libs/python37.lib (ver 3.7.9)  
numpy: C:/Python37/Lib/site-packages/numpy/core/include (ver 1.19.2)  
install path: C:/Python37/Lib/site-packages/cv2/python-3.7

Python (for build): C:/cygwin/bin/python2.7.exe

Java:  
ant: NO  
JNI: NO  
Java wrappers: NO  
Java tests: NO

## Install to: D:/devel/opencv/BuildRelease/install

python \>\>\>

---

<div class="post-metadata">

**Author:** ![sturkmen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sturkmen/32/13_2.png) [@sturkmen](https://forum.opencv.org/u/sturkmen)\
**Post date:** [February 1, 2022, 2:29pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/10 "2022-02-01T14:29:58Z")

</div>

you need to upgrade to version:4.5.5 [ChangeLog · opencv/opencv Wiki · GitHub](https://github.com/opencv/opencv/wiki/ChangeLog#version455)

---

<div class="post-metadata">

**Author:** ![mattia](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@mattia](https://forum.opencv.org/u/mattia)\
**Post date:** [February 1, 2022, 2:34pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/11 "2022-02-01T14:34:48Z")

</div>

I’m using the open cv library built-in touchdesigner i don’t know how can i upgrade it, i don’t even know if is possible.  
So with the version installed is not possible to read the decoded data?

---

<div class="post-metadata">

**Author:** ![sturkmen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sturkmen/32/13_2.png) [@sturkmen](https://forum.opencv.org/u/sturkmen)\
**Post date:** [February 1, 2022, 3:41pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/12 "2022-02-01T15:41:17Z")

</div>

> **[Experimental 2021.38110](https://derivative.ca/release/experimental-202138110/65595)**
>
> Experimental Builds Experimental builds include new features still in development and testing, features are subject to change. For the stability and reliability required for performances and project deliveries, we recommend using the production ready...

experimental release have **OpenCV 4.5.2**

try to get help on [https://forum.derivative.ca/](https://forum.derivative.ca/)

---

<div class="post-metadata">

**Author:** ![mattia](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@mattia](https://forum.opencv.org/u/mattia)\
**Post date:** [February 1, 2022, 3:45pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/13 "2022-02-01T15:45:49Z")

</div>

Thanks a lot for your help! i will definetly test it on experimental altough for my project i will need a stable version since experimental have a lot of bug right now and is not usable in production, in the mean time i have also ask on touchdesigner forum

---

<div class="post-metadata">

**Author:** ![sturkmen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sturkmen/32/13_2.png) [@sturkmen](https://forum.opencv.org/u/sturkmen)\
**Post date:** [February 1, 2022, 3:52pm UTC](https://forum.opencv.org/t/qr-code-detection/7372/14 "2022-02-01T15:52:46Z")

</div>

OpenCV 4.5.2 have **WeChat QRCode Detector** you can try it if you install the last experimental release of Touchdesigner

> <https://github.com/opencv/opencv_contrib/blob/4.x/modules/wechat_qrcode/samples/qrcode.py>
