Python Forum
qrcode detector not in cv2 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: qrcode detector not in cv2 (/thread-29683.html)



qrcode detector not in cv2 - Pedroski55 - Sep-15-2020

I am just following the instructions here, trying to learn how this works.

I am now trying to read a qr code I made.

this shows no errors:

Quote:# read the QRCODE image
img1 = cv2.imread("myQR_blue.png")

But this does not work:

Quote:# initialize the cv2 QRCode detector
detector = cv2.QRCodeDetector() # whoops, doesn't work!

I get this in Idle:

Quote:>>> detector = cv2.QRCodeDetector()
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
detector = cv2.QRCodeDetector()
AttributeError: module 'cv2' has no attribute 'QRCodeDetector'

The webpage says it was updated September 2020.

I installed cv2 from Ubuntu: sudo apt-get install python3-opencv

How do I get the detector?


RE: qrcode detector not in cv2 - bowlofred - Sep-15-2020

If you do dir(cv2) in your REPL, do you get lots and lots of objects? Could you show some of the output?

If you don't, I suspect your cv2 module is being shadowed by some other file locally.

>>> len(dir(cv2))
1946
>>> dir(cv2)
['', 'ACCESS_FAST', 'ACCESS_MASK', 'ACCESS_READ', 'ACCESS_RW', 'ACCESS_WRITE', 'ADAPTIVE_THRESH_GAUSSIAN_C', 'ADAPTIVE_THRESH_MEAN_C', 'AGAST_FEATURE_DETECTOR_AGAST_5_8', 'AGAST_FEATURE_DETECTOR_AGAST_7_12D', 'AGAST_FEATURE_DETECTOR_AGAST_7_12S', 'AGAST_FEATURE_DETECTOR_NONMAX_SUPPRESSION', 'AGAST_FEATURE_DETECTOR_OAST_9_16', 'AGAST_FEATURE_DETECTOR_THRESHOLD', 'AKAZE', 'AKAZE_DESCRIPTOR_KAZE', 'AKAZE_DESCRIPTOR_KAZE_UPRIGHT', 'AKAZE_DESCRIPTOR_MLDB',
...



RE: qrcode detector not in cv2 - Pedroski55 - Sep-16-2020

EDIT: SOLVED: with advice from askubuntu, I downloaded

pedro@pedro-512ssd:~$ pip3 install opencv-contrib-python

Now the detector works!!

Thanks for the reply:

I got this info:

Quote:>>> cv2
<module 'cv2' from '/usr/lib/python3/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so'>
>>> len(dir(cv2))
1704
>>> dir(cv2) (gives "squeezed text" because the output is very long)

>>>

Looks like my cv2 is significantly shorter than your cv2 1704 to 1946!

Maybe that's why the module is missing!

How to change this? I have tried to install opencv- from pip3, but the install fails.

Quote:pedro@pedro-512ssd:~$ pip3 install opencv-python
Collecting opencv-python
Using cached https://files.pythonhosted.org/packages/77/f5/49f034f8d109efcf9b7e98fbc051878b83b2f02a1c73f92bbd37f317288e/opencv-python-4.4.0.42.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-aop87qrl/opencv-python/setup.py", line 9, in <module>
import skbuild
ModuleNotFoundError: No module named 'skbuild'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-aop87qrl/opencv-python/