dwalton76 / rubiks-cube-tracker

Given an image of a rubiks cube, find the RGB value for each square.
MIT License
129 stars 36 forks source link

confusing between red and orange #12

Closed apurvakalia closed 1 year ago

apurvakalia commented 1 year ago

The cube scanning seems to be confusing between red and orange for me. I have tried Pi Camera v1.3 as well as v2.0. I have also tried multiple cubes and played around with many settings (AWB gains, contrast, mode etc), but it still gets confused between red and orange on alternate squares. See the attached file - which is the output from the color-resolver program.

rubiks-color-resolver.html.zip

dwalton76 commented 1 year ago

Red vs. Orange is always a beast :( I am able to reproduce the problem with the output from the html file you attached (thanks)...let me see what I can do

apurvakalia commented 1 year ago

Thanks for responding so quickly. A couple of other things that may be important:

dwalton76 commented 1 year ago

image

question...is square 23 Orange and square 41 Red or is it the other way around?

apurvakalia commented 1 year ago

I think that is the problem. The actual cube looks like this: IMG-7730 IMG-7731

So by that 23 should be Red, right? The dictionary of returned RGB values shows: '23': (230, 61, 33) ... '41': (180, 0, 7)

If 41 is orange as per the actual cube pictures, then the RGB values seem good (230 is "more" red than 180).

So am I spinning the cube the wrong way in between scans? Or is it some other problem?

dwalton76 commented 1 year ago

yeah so 23 is Red and 41 is Orange...so we are getting the centers and corners correct but the orange vs red edges are all reversed.
image

You are not doing anything wrong...I suspect this is a bug:

apurvakalia commented 1 year ago

Yes, the edges seem to be getting flipped. The RGB values of the edges look good (e.g. '20': (224, 54, 29) vs '38': (172, 0, 5)). So it does look like a bug.....

dwalton76 commented 1 year ago

I see what was wrong and pushed a fix, do sudo python3 -m pip install git+https://github.com/dwalton76/rubiks-color-resolver.git to install the latest code from the repo with the fix and let me know if it works

apurvakalia commented 1 year ago

wow! that was quick. Unfortunately, I wont get to testing this later today, but I will try and match your alacrity and let you know as soon as I test it out :) Do I need to uninstall the current install before pulling in the fix? Also, just out of curiosity, what was the bug?

dwalton76 commented 1 year ago

In a nutshell we were looking at all of the corner squares and classifying them as one of the six colors and we used that to define a baseline RGB for each of the six colors. For an odd cube though we can do a little better by only using the square in the dead center of each side for defining a baseline RGB for each of the six colors. For odd cubes we know that:

so that makes it much easier to get them classified as one of the size colors correctly.

apurvakalia commented 1 year ago

Your fix worked! I can now successfully scan the cube 4 times out of 5. Every once in a while the cube becomes a little skewed while turning and then the scanner complains about not finding the black border, but that is a mechanical issue. I need to adjust my flipper so that the cube does not get skewed. Thanks a lot - I am now moving to the next part. Hopefully I can get this working for BuildHat soon....