AlpacaTechJP/selectivesearch

TypeError occurs

happyguys97 opened this issue · 5 comments

I get the type error
the source code is as follows:
img = skimage.data.astronaut()
img_lbl, regions = selectivesearch.selective_search( img, scale=500, sigma=0.9, min_size=10)


the result is (Python 3.5)
Traceback (most recent call last):
File ".../test/tset.py", line 9, in
img_lbl, regions = selectivesearch.selective_search( img, scale=500, sigma=0.9, min_size=10)
File "C:\Program Files\Anaconda3\lib\site-packages\selectivesearch\selectivesearch.py", line 274, in selective_search
neighbours = _extract_neighbours(R)
File "C:\Program Files\Anaconda3\lib\site-packages\selectivesearch\selectivesearch.py", line 208, in _extract_neighbours
for cur, a in enumerate(R[:-1]):
TypeError: 'dict_items' object is not subscriptable

Could you fix this problem? Please help me.

In python 3.X, mydict.keys() does not return a subscriptable array. Thus R is not subscriptable

Thus you need to change the line 208 in file selectivesearch.py, to

R = list(R)                                   # this is added
for cur, a in enumerate(R[:-1]):

You can change the file like this:
1、locate directory to your package: C:\Anaconda3\Lib\site-packages\selectivesearch
2、then open the file:"_init.py" and add "." behand selectivesearch like this: from .selectivesearch import selective_search # NOQA
3、open the file named "selectivesearch.py", and then import header: from functools import cmp_to_key
4、change the 206 lines like this: R = list(regions.items())
5、change the 289 lines like this: i, j = sorted(S.items(), key=cmp_to_key(lambda a, b: a[1]-b[1]))[-1][0]

Everything is clear now.
Thanks for your support.

Because the author has abandoned the repo.
Hi,I want to ask does the order of the final returned results follow the ascending order of the scores?
How can I see the score information in this program?
Best wishes!