Skip to content

basic operation python tutorial still mentions itemset #26035

@knmcguire

Description

@knmcguire

Describe the doc issue

The documentation on basic image operations still mentions that we can set a pixel value with numpy's itemset since that is faster than accessing it through the index

This results in the following error:

Traceback (most recent call last):
  File ".../opencv_ws/scripts/basic_image_operations.py", line 18, in <module>
    img.itemset((10,10,2),100)
    ^^^^^^^^^^^
AttributeError: `itemset` was removed from the ndarray class in NumPy 2.0. Use `arr[index] = value` instead.

Fix suggestion

We can remove those instructions. Also in numpy's migration guide from 1 to version 2.0 they also advise the same as the error message said: https://numpy.org/devdocs/numpy_2_0_migration_guide.html#ndarray-and-scalar-methods

The only thing is is that I can't find if they have solved the issue of the direct setting method being slower.

Another solution that we can do instead is we can also consider fixing the numpy version in install_requirements to install the latest of numpy 1 and not 2, as now it will just install the latest.

install_requires="numpy",

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions