QR code detection

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

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

null1

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

qrcode
This is the qr code

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?

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
.
.
.

1 Like

I have points but not decode_info :triumph:

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)

what is print(cv.getBuildInformation())

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 >>>

you need to upgrade to version:4.5.5 ChangeLog · opencv/opencv Wiki · GitHub

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?

experimental release have OpenCV 4.5.2

try to get help on https://forum.derivative.ca/

1 Like

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

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