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

TypeError: 'dict_items' object is not subscriptable #26

Closed
root-sudip opened this issue Aug 7, 2017 · 2 comments
Closed

TypeError: 'dict_items' object is not subscriptable #26

root-sudip opened this issue Aug 7, 2017 · 2 comments

Comments

@root-sudip
Copy link

I was doing exactly same code that has in the example in selectivesearch.

here is the code,

import skimage.data
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from selectivesearch import selective_search


def main():

    # loading astronaut image
    img = skimage.data.astronaut()

    # perform selective search
    img_lbl, regions = selective_search(img, scale=500, sigma=0.9, min_size=10)

    candidates = set()
    for r in regions:
        # excluding same rectangle (with different segments)
        if r['rect'] in candidates:
            continue
        # excluding regions smaller than 2000 pixels
        if r['size'] < 2000:
            continue
        # distorted rects
        x, y, w, h = r['rect']
        if w / h > 1.2 or h / w > 1.2:
            continue
        candidates.add(r['rect'])

    # draw rectangles on the original image
    fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
    ax.imshow(img)
    for x, y, w, h in candidates:
        print(x, y, w, h)
        rect = mpatches.Rectangle(
            (x, y), w, h, fill=False, edgecolor='red', linewidth=1)
        ax.add_patch(rect)

    plt.show()

if __name__ == "__main__":
    main()

and getting this error,

Traceback (most recent call last):
  File "selective_search.py", line 41, in <module>
    main()
  File "selective_search.py", line 13, in main
    img_lbl, regions = selective_search(img, scale=500, sigma=0.9, min_size=10)
  File "/usr/local/lib/python3.5/dist-packages/selectivesearch/selectivesearch.py", line 274, in selective_search
    neighbours = _extract_neighbours(R)
  File "/usr/local/lib/python3.5/dist-packages/selectivesearch/selectivesearch.py", line 208, in _extract_neighbours
    for cur, a in enumerate(R[:-1]):
TypeError: 'dict_items' object is not subscriptable

To fix this error, I have changed the line number 206 of selectivesearch.py by this line R = list(regions.items())
Now I am getting this error,

Traceback (most recent call last):
  File "selective_search.py", line 41, in <module>
    main()
  File "selective_search.py", line 13, in main
    img_lbl, regions = selective_search(img, scale=500, sigma=0.9, min_size=10)
  File "/usr/local/lib/python3.5/dist-packages/selectivesearch/selectivesearch.py", line 286, in selective_search
    i, j = sorted(S.items(), cmp=lambda a, b: cmp(a[1], b[1]))[-1][0]
TypeError: 'cmp' is an invalid keyword argument for this function

How do I fix this problem ??

@root-sudip
Copy link
Author

I am using pyhton3.5,

@root-sudip
Copy link
Author

root-sudip commented Aug 7, 2017

I got the solution from here

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

1 participant