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

Exception when running #1

Closed
xpromache opened this issue Dec 26, 2019 · 6 comments
Closed

Exception when running #1

xpromache opened this issue Dec 26, 2019 · 6 comments

Comments

@xpromache
Copy link

Hello,

I was trying your set solver (after having thought myself to write one) and I get an error for the attached image.

Traceback (most recent call last):
  File "./solve_set.py", line 45, in 
    main()
  File "./solve_set.py", line 35, in main
    game.solve()
  File "git/set-solver/SetGame.py", line 120, in solve
    self.get_cards()
  File "git/set-solver/SetGame.py", line 60, in get_cards
    card.label = classify_card_from_im(card.im)
  File "git/set-solver/classify_card.py", line 120, in classify_card_from_im
    color = classify_color(card_im)
  File "git/set-solver/classify_card.py", line 97, in classify_color
    unclassified_rgb = shape_rgb(card_im)
  File "git/set-solver/classify_card.py", line 82, in shape_rgb
    shrunk_im = noteshrink_card_from_im(card_im)
  File "git/set-solver/process_card.py", line 34, in noteshrink_card_from_im
    noteshrunk_file = noteshrink_card_from_file(tmp_file)
  File "git/set-solver/process_card.py", line 56, in noteshrink_card_from_file
    palette = noteshrink.get_palette(samples, options)
  File "git/set-solver/vendor/noteshrink.py", line 395, in get_palette
    iter=kmeans_iter)
  File "python-virtual-environments/solv/lib/python3.6/site-packages/scipy/cluster/vq.py", line 455, in kmeans
    guess = _kpoints(obs, k)
  File "python-virtual-environments/solv/lib/python3.6/site-packages/scipy/cluster/vq.py", line 476, in _kpoints
    idx = np.random.choice(data.shape[0], size=k, replace=False)
  File "mtrand.pyx", line 1120, in mtrand.RandomState.choice
ValueError: a must be greater than 0

set2

@nicolashahn
Copy link
Owner

nicolashahn commented Dec 28, 2019

I'm able to reproduce, it appears to be failing on the first image in the second column. It's unable to detect any foreground (shape) pixels because of the reflection on the card, it's classifying all of them as the white background of the card. I can add a patch to prevent it from crashing when it happens, but it will still fail to find any sets that include that card. I would recommend taking the photo again in a way that there isn't glare on any of the cards. Sorry I don't have a better solution for you.

@xpromache
Copy link
Author

xpromache commented Dec 28, 2019 via email

@nicolashahn
Copy link
Owner

nicolashahn commented Dec 28, 2019

Not that tedious, label_all_cards.py already has functionality for that. Try pulling master and running it again. (edit: I mean running the original solve_set.py command with your image, not label_all_cards.py)

@xpromache
Copy link
Author

Thanks for a fix but now it crashes:

./solve_set.py /tmp/set2.jpeg 
Initialize OpenCL runtime...
Could not classify at least one of the attributes of this card. Please enter the attribute labels manually.
Select the window with the card image when entering keys. Keys entered here will not be registered.
Enter the card's COLOR:
  For RED, enter '1'
  For GREEN, enter '2'
  For PURPLE, enter '3'
If not a card, enter 'n': 
QObject::moveToThread: Current thread (0x2b2eb20) is not the object's thread (0x2adb540).
Cannot move to target thread (0x2b2eb20)

Segmentation fault (core dumped)

@nicolashahn
Copy link
Owner

I'm not able to reproduce. Which OS, version of OpenCV, and version of python are you using? Are you able to get any cv2 GUI window to appear? For example, are you able to run the code in this post? opencv/opencv-python#46 (comment)

@xpromache
Copy link
Author

I reinstalled opencv from the distribution and it works wonderfully now!

Finally we are certain there was no set in the combination we struggled with one week ago :)

Thanks!

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

2 participants