Skip to content

Fix howdy test crash under NumPy 2.x (histogram scalar indexing) - #1137

Open
mdj2812 wants to merge 1 commit into
boltgolt:masterfrom
mdj2812:fix/test-histogram-numpy2
Open

Fix howdy test crash under NumPy 2.x (histogram scalar indexing)#1137
mdj2812 wants to merge 1 commit into
boltgolt:masterfrom
mdj2812:fix/test-histogram-numpy2

Conversation

@mdj2812

@mdj2812 mdj2812 commented Aug 10, 2026

Copy link
Copy Markdown

Fixes #1136

sudo howdy test crashes with IndexError: invalid index to scalar variable when running on NumPy 2.x.

OpenCV 5.x returns cv2.calcHist results as a 1-D array ((8,)), so sum(hist)[0] and value[0] no longer apply. This change uses:

  • int(np.sum(hist)) instead of int(sum(hist)[0])
  • float(value.item()) instead of float(value[0])

This works with both the (8, 1) arrays returned by OpenCV 4.x and the (8,) arrays returned by OpenCV 5.x, on NumPy 1.x and 2.x alike.

Tested with NumPy 2.5.2; the existing (OpenCV 4.x style) histogram layout also keeps working.

OpenCV 5 returns calcHist results as a 1-D array, so indexing sum(hist)[0]
and value[0] fails. Use np.sum and .item() instead, which work with both
the (8,1) arrays returned by OpenCV 4.x and the (8,) arrays returned by
OpenCV 5.x, on NumPy 1.x and 2.x alike.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

howdy test crashes with NumPy 2.x due to scalar indexing

1 participant