Python bindings for graycode failing to find generate function

Hi all,

I have recently installed the open-cv-contrib using pip with version 4.5.5.64

according to documentation (and an old code base of mine), the class cv2.structured_light_GrayCodePattern should have a “generate()” function exposed, that allows creating graycode patterns as expected by the decode method.

but when I run the following snippet, it failes with the following error:

import cv2
graycode = cv2.structured_light_GrayCodePattern.create(512,512)
graycode.generate()

“AttributeError: ‘cv2.structured_light_GrayCodePattern’ object has no attribute ‘generate’”

why does this happen? where did generate disappear?

Its documented and working for me, are you sure you have the contrib module installed?

>>> help(cv2.structured_light.GrayCodePattern.generate)
Help on method_descriptor:

generate(...)
    generate([, patternImages]) -> retval, patternImages
    .   @brief Generates the structured light pattern to project.
    .
    .      @param patternImages The generated pattern: a vector<Mat>, in which each image is a CV_8U Mat at projector's resolution.

well it is here (self-built 4.6.0)

>>> graycode = cv2.structured_light_GrayCodePattern.create(5,5)
>>> graycode.generate()
(True, (array([[  0,   0,   0,   0, 255],
       [  0,   0,   0,   0, 255],
       [  0,   0,   0,   0, 255],
       [  0,   0,   0,   0, 255],
       [  0,   0,   0,   0, 255]], dtype=uint8), array([[255, 255, 255, 255,   0],
       [255, 255, 255, 255,   0],
       [255, 255, 255, 255,   0],
       [255, 255, 255, 255,   0],
       [255, 255, 255, 255,   0]], dtype=uint8), array([[  0,   0, 255, 255, 255],
       [  0,   0, 255, 255, 255],
       [  0,   0, 255, 255, 255],
       ....

cant find the correct issue / pr, but there was something in the pip build scripts, removing interfaces (to save space in the binary) and it should be repaired now

but luckily, as of today (!) 4.6.0 release is out !!
just try to un/reinstall via pip

I am certain the contrib module is installed. I did pip list and it is right there.

are you using the exact version i mentioned? the call

help(cv2.structured_light.GrayCodePattern.generate)

produces for me:

AttributeError: module 'cv2.structured_light' has no attribute 'GrayCodePattern'

which I think hints you are using an older version?

can you try to update (via pip), and report back, please ?

currently pypi does not contain this update:

it reports latest version is 4.5.5.64
so pip uninstall / reinstall just installs the same version.

is there any other way to obtain the wheel directly?

P.S I am doing:
pip uninstall opencv-contrib-python
pip install opencv-contrib-python

ah right, (did not look at pypi … ).
maybe wait a day or 3 for it to be updated.
if you’re really into it, build from src
(not nessecarily the wheel, which is a far more complicated thing).

again, i’m (almost) sure, this is a temporary, pypi related problem

So when you try to install this specific version (4.5.5.64), and run the command i ran, it reproduces for you also?

Just making sure I am not losing my mind here :slight_smile:

Just making sure I am not losing my mind here

we can’t let that happen !
problem reproduced on colab :wink:

Problem solved with version 4.6.0.66

thank you for the kind replies !

1 Like