Fix howdy test crash under NumPy 2.x (histogram scalar indexing) - #1137
Open
mdj2812 wants to merge 1 commit into
Open
Fix howdy test crash under NumPy 2.x (histogram scalar indexing)#1137mdj2812 wants to merge 1 commit into
mdj2812 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1136
sudo howdy testcrashes withIndexError: invalid index to scalar variablewhen running on NumPy 2.x.OpenCV 5.x returns
cv2.calcHistresults as a 1-D array ((8,)), sosum(hist)[0]andvalue[0]no longer apply. This change uses:int(np.sum(hist))instead ofint(sum(hist)[0])float(value.item())instead offloat(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.