Ask Your Question
0

3D reconstruction of Rubik's cube. Did you try it?

asked 2018-01-31 01:55:18 -0600

updated 2020-11-06 19:33:21 -0600

The task seems elementary at first glance, but try and it turns out to be tricky. Meanwhile this is just a geometric puzzle and a perfect application for various OpenCV methods. Enjoy. I don't ask about solving it or color detection. It is regarded just as a box.image descriptionimage descriptionimage descriptionimage descriptionAs computer vision practitioners have already guessed, the pictures presented are the best. Just turn it 40 degrees and the perfect result goes bust. Detecting contours works better, but it is rather time-consuming. It produces many duplicates. I tried Canny only.image description You see that many squares are lost because their contours were rejected. If I replace

approx.size()==4&&fabs(contourArea(Mat(approx)))>100&&isContourConvex(Mat(approx)))

by

fabs(contourArea(Mat(approx)))> 100)

they appear and the central knot may be detected.image descriptionAnother shortcoming of contours. Probably they are the best for this concrete task, but I hope that my program will work for other boxes too. They have no squares. The typical pattern is lines of text intermingled with some pictures. I still believe that line detection has perspectives. Not only the functions used, but also their sequence matters. Initially, I converted color image to gray, then fed it to Canny. squares.cpp hints another approach. We can extract separate channels, apply Canny,image description then mix results.image description Almost perfect edges make it possible to reconstruct 3 necessary lines.image description

edit retag flag offensive close merge delete

Comments

and question is ?

LBerger gravatar imageLBerger ( 2018-01-31 02:08:43 -0600 )edit

The question is, did anybody here try this particular object. It is standardized, widely available, and was designed especially for educational purposes. I see a lot of discussion possible.

ya_ocv_user gravatar imageya_ocv_user ( 2018-01-31 03:52:17 -0600 )edit

i met plenty of sample source code related this. the method in your pictures seems not a robust one.

sturkmen gravatar imagesturkmen ( 2018-01-31 05:00:49 -0600 )edit

That's right. This is exactly the reason why I ask here. Would you please provide links to those samples?

ya_ocv_user gravatar imageya_ocv_user ( 2018-02-02 03:19:08 -0600 )edit
1

take a look at this

sturkmen gravatar imagesturkmen ( 2018-02-02 04:37:03 -0600 )edit

Great. Looks like a lot of people (including you yourself) have already tried this task. I heard of a robot that solves Rubik's cube. You provided the link to some source code. I need some time to cope with this all. Maybe the next week will post here what I think.

ya_ocv_user gravatar imageya_ocv_user ( 2018-02-02 06:26:12 -0600 )edit

IMO the task which you discussed with nadley is simpler. It may be designated as "understanding". At the input we have an array of equivalent pixels. At the output - quite different data. Namely, the list of symbols representing colors and their order. I don't want symbolic output for now. Just to convert 2D -> 3D. In theory, the task is elementary. Find the central knot where 3 edges come together, determine the opposite ends of these lines, and the job is done. We have 3 coordinate axes linked to the cube. Now the reality. The features which I enumerate further are typical. You will often encounter them on other objects by accident, but here they are a part of the design so may be thoroughly discussed.

ya_ocv_user gravatar imageya_ocv_user ( 2018-02-05 01:53:46 -0600 )edit

1.Each edge of the cube is represented not by 1, but by 2 parallel lines (sides of squares). 2.Each line is broken. This was already addressed in OpenCV. HoughLinesP() has a parameter maxLineGap to fill gaps. 3.Canny edge detector requires gray input, but when you convert colors, they produce different intensity. As a result, white ant yellow squares are perfectly recognized, brown disappears at all, others partly disappear and contours won't be linear.

ya_ocv_user gravatar imageya_ocv_user ( 2018-02-05 01:55:54 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-02-05 14:51:23 -0600

updated 2018-02-05 14:52:22 -0600

you can use squares.cpp with small modification like below

            if( approx.size() == 4 &&
                fabs(contourArea(Mat(approx))) > 100 &&   // --------change 1000 to 100
                isContourConvex(Mat(approx)) )
            {
                double maxCosine = 0;

                for( int j = 2; j < 5; j++ )
                {
                    // find the maximum cosine of the angle between joint edges
                    double cosine = fabs(angle(approx[j%4], approx[j-2], approx[j-1]));
                    maxCosine = MAX(maxCosine, cosine);
                }

                // if cosines of all angles are small
                // (all angles are ~90 degree) then write quandrange
                // vertices to resultant sequence
                //if( maxCosine < 0.3 )  // -----------------comment this line

image description

i think you can use those countours to reconstruct 3D shape of the cube.

edit flag offensive delete link more

Comments

I understand the idea of your modifications. squares.cpp takes only big rectangular objects.

ya_ocv_user gravatar imageya_ocv_user ( 2018-02-06 01:05:50 -0600 )edit

The outlines are so thick because it detects many contours for each square.

ya_ocv_user gravatar imageya_ocv_user ( 2018-02-06 23:31:57 -0600 )edit

He checks 11 different threshold levels and piles all contours together. Maybe worth using some more efficient method?

ya_ocv_user gravatar imageya_ocv_user ( 2018-02-06 23:56:39 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-01-31 01:55:18 -0600

Seen: 1,861 times

Last updated: Feb 12 '18