• Welcome to the Speedsolving.com, home of the web's largest puzzle community!
    You are currently viewing our forum as a guest which gives you limited access to join discussions and access our other features.

    Registration is fast, simple and absolutely free so please, join our community of 40,000+ people from around the world today!

    If you are already a member, simply login to hide this message and begin participating in the community!

Reading Rubik's Cube states into computer using Computer Vision magic

badmephisto

Member
Joined
Aug 29, 2007
Messages
836
YouTube
Visit Channel
I thought some people might be interested: here are some results from my Computer Vision project:

http://www.youtube.com/watch?v=VaW1dmqRE0o

It dealt with a better/faster way to read in a state of a rubiks cube so that you can enter any particular configuration into solvers quickly, or just share some configuration with other people.

Implemented in Python and OpenCV library.

I haven't quite figured out what I can port the resulting configuration to yet

Also the code is NOT online, but I may post it sometime later... for now just sharing it with everyone!
EDIT: ah what the hell here is the code and my report:
http://www.cs.ubc.ca/~andrejk/525project/
 
Last edited:

Chapuunka

Member
Joined
Feb 4, 2010
Messages
879
Location
USA
WCA
2010JUDD01
I could see this being on every computer with a webcam pretty soon. That would be pretty cool.

I also saw your videos about the evolutions of simple organisms. That was actually pretty fascinating.
 

badmephisto

Member
Joined
Aug 29, 2007
Messages
836
YouTube
Visit Channel
Lucas: good idea.
I suspect that it would suffer from lighting problems as riffz suggested.
It would also be harder to align it exactly toward the camera in that way and much harder to hold it in a way as to not cause occlusions.

The detection itself is also not to be trusted TOO much. It is more reliable if it is ok to get it slightly wrong, which is the case for a single face, but most likely not for 3 faces. Not enough wiggle.

And yes riffz thats the channel I usually post my programming stuff on. I just need to sometimes share results of some of my programs with other people and thats mostly what i use it for. In this case that someone was my prof for the class :p
 

bamboocha

Member
Joined
Apr 12, 2009
Messages
43
Location
Finland
YouTube
Visit Channel
Sorry for me being a noob but how do I run this program? I downloaded Python 2.6 and OpenCV 2.1 with bindings and numpy library.

When I try to run it I get an error:

Code:
Traceback (most recent call last):
  File "C:\folders\cubefinder.py", line 2, in <module>
    import cv
ImportError: No module named cv
 

badmephisto

Member
Joined
Aug 29, 2007
Messages
836
YouTube
Visit Channel
Sorry for me being a noob but how do I run this program? I downloaded Python 2.6 and OpenCV 2.1 with bindings and numpy library.

When I try to run it I get an error:

Code:
Traceback (most recent call last):
  File "C:\folders\cubefinder.py", line 2, in <module>
    import cv
ImportError: No module named cv

Pretty simple, OpenCV install didn't go right. Check out their install directions more closely. When I installed it they required me to copy the cv.pyd files into Python/Lib/site-packages folder but maybe they have a more automatic way in their newer install
 

Crosshash

Member
Joined
Dec 14, 2009
Messages
81
Very interesting. Are you going to elaborate on this code some more?

I'm wondering if the question you asked in the other thread was related to making sure all the colours matched up correctly so you could solve the cube based on colour input only. Would be very interesting to see it.

I wish I could read your code more easily but I've never used Python before (i study Java), was the reason for using an edge detector in order to identify the cube in the image?
 

PatrickJameson

Premium Member
Joined
Apr 15, 2008
Messages
996
Location
Buffalo, NY
WCA
2007JAME01
YouTube
Visit Channel
I was going to delete the above two posts, infract, and move on but this gave me a nice little project for the next three days(or less, depending on how long it takes and how far I go with it) since I have have a slight break from robotics. I've been dealing with a bit of object tracking stuff for robotics already. Should be fun. I'll probably just use Java and v4l4j since I used it for the linked video already.
 
Joined
Nov 29, 2008
Messages
214
This thread is dead since 2011 but since I are also do some experiments with Python and OpenCV I decided to revive it instead of creating a new thread. The link http://www.cs.ubc.ca/~andrejk/525project/ from above also is dead and I want to ask if anybody here has a copy of the code or a working link because I am interested in the code.

With my approach I put a grid on a video frame (gridsize about 25x35) and compute the average hue values and the variance of the hue values in a grid-square. Squares with low variances are candidates for a square which is situated completely inside a cube facelet. Omitting some details in the end I have I binary mask which I search for squares using the openCV findContours and approxPolyDP functions. This works best for cubes where the facelets are well separated of course. In this way I can detect all facelets within the picture.

The color detection itself I also use the hsv-values, h to decide the color of all non-white facelets, white faclets are detected by low s values and high v values. Distingushing between red and orange in advance is probably impossible, it depends on the colors of the actual cube and to some extend also on the light source. At least you have to know the hue range fo an orange sticker.
Here is an example: http://kociemba.org/videos/cuberec.mp4

I plan to integrate the computer vision part into my Python cubesolver project https://github.com/hkociemba/RubiksCube-TwophaseSolver as soon as possible.
 

abunickabhi

Member
Joined
Jan 9, 2014
Messages
6,682
Location
Yo
WCA
2013GHOD01
YouTube
Visit Channel
This thread is dead since 2011 but since I are also do some experiments with Python and OpenCV I decided to revive it instead of creating a new thread. The link http://www.cs.ubc.ca/~andrejk/525project/ from above also is dead and I want to ask if anybody here has a copy of the code or a working link because I am interested in the code.

With my approach I put a grid on a video frame (gridsize about 25x35) and compute the average hue values and the variance of the hue values in a grid-square. Squares with low variances are candidates for a square which is situated completely inside a cube facelet. Omitting some details in the end I have I binary mask which I search for squares using the openCV findContours and approxPolyDP functions. This works best for cubes where the facelets are well separated of course. In this way I can detect all facelets within the picture.

The color detection itself I also use the hsv-values, h to decide the color of all non-white facelets, white faclets are detected by low s values and high v values. Distingushing between red and orange in advance is probably impossible, it depends on the colors of the actual cube and to some extend also on the light source. At least you have to know the hue range fo an orange sticker.
Here is an example: http://kociemba.org/videos/cuberec.mp4

I plan to integrate the computer vision part into my Python cubesolver project https://github.com/hkociemba/RubiksCube-TwophaseSolver as soon as possible.

Good initiative and all the best!
 
Joined
Nov 29, 2008
Messages
214
Faster than I thought I was able to integrate the computervision part. The files are uploaded to Github now. Here is an example how the parts work together:

http://kociemba.org/videos/visiongui.avi

Yet some critical explanations are missing how to handle the sliders for the filters which is quite essential to achieve a good recognition rate...
 
Top