Ask Your Question

Revision history [back]

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.

you can use squares.cpp with small modification like below

            if( approx.size() == 4 &&
                fabs(contourArea(Mat(approx))) > 100 &&   // -----------------change --------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.