Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while executing the code #1

Open
wasimswdev opened this issue May 12, 2019 · 4 comments
Open

Error while executing the code #1

wasimswdev opened this issue May 12, 2019 · 4 comments

Comments

@wasimswdev
Copy link

I am using opencv version 3.4.1 and numpy 1.16.2 i have used a jpg file while executing the code i got the following error

File "C:\Users\Administrator\Anaconda3\lib\site-packages\numpy\lib\histograms.py", line 410, in _get_bin_edges
n_equal_bins = operator.index(bins)
TypeError: 'numpy.float64' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "1D Illuminant invariant image.py", line 58, in
(hist,waste)=np.histogram(temp,bins=nbins)

File "C:\Users\Administrator\Anaconda3\lib\site-packages\numpy\lib\histograms.py", line 780, in histogram
bin_edges, uniform_bins = _get_bin_edges(a, bins, range, weights)

File "C:\Users\Administrator\Anaconda3\lib\site-packages\numpy\lib\histograms.py", line 413, in _get_bin_edges
'bins must be an integer, a string, or an array')

TypeError: bins must be an integer, a string, or an array

@maja601
Copy link

maja601 commented May 14, 2019

Hi,

as you expected, the error occurs because of the numpy (and therefore also opencv) version.
There should be two ways to solve this issue:

  1. Use a different numpy (& opencv) version. This can be done by:
    pip uninstall numpy
    pip uninstall opencv-python
    and then get the proper older version:
    pip install opencv-python==3.1.0
    This automatically installs the right numpy version as well (1.11.1)
    Please use a virtualenv for all this.

  2. Change line 57 in the code: nbins should be an integer, so i would recommend np.int here

I hope it helps and all the best!

@nirmalsnair
Copy link

You need to add np.int_() in this line also.

mX1sort2 = np.int_(np.divide(mX1sort, mX.shape[1]))

Dont't know if its logically correct.

@pavannaikmu
Copy link

Hi,
the error is still the same did u all get the solution......

@medoedka
Copy link

medoedka commented Oct 6, 2021

Hi, the error is still the same did u all get the solution......

I've fixed it by adding a new row:
nbins=int(nbins)
between 57 and 58 lines of code.

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

No branches or pull requests

5 participants