How detect long edges of wall to prepare mask and recolor

Jigar Parekh picture Jigar Parekh · Apr 19, 2013 · Viewed 7.7k times · Source

Main idea is to allow user to recolor to specific wall based user selection. Currently i have implemented this feature using cvFloodFill (helps to prepare mask image) which can help me to change relative HSV value for wall so i can retain edges. but problem with this solution is that it works on color and all walls are repainted instead of single wall selected by user.

i have also tried canny edge detection but it just able to detect edge but not able to convert it to area.

Please find below code which i am currently using for repaint function

  1. Prepare mask

    cvFloodFill(mask, new CvPoint(295, 75), new CvScalar(255, 255, 255,0), cvScalarAll(1), cvScalarAll(1), null, 4, null);

  2. split channel

    cvSplit(hsvImage, hChannel, sChannel, vChannel, null);

  3. change color

    cvAddS(vChannel, new CvScalar(255*(0.76-0.40),0,0,0), vChannel, mask);

How can we detect edges and corresponding area from the image.

i am looking for solution which can be other than opencv but should be possible for iPhone and android

Sample image

Edit

i am able to achieve somewhat result as below image using below steps

cvCvtColor(image, gray, CV_BGR2GRAY);   
cvSmooth(gray,smooth,CV_GAUSSIAN,7,7,0,0);
cvCanny(smooth, canny, 10, 250, 5);

there are two problem with this output not sure how to resolve them 1. close near by edges 2. remove small edges

enter image description here

Answer

Thom picture Thom · Apr 24, 2013

You could try something like :

 Mat imageOut = Mat::zeros(imageIn.rows, imageIn.cols, CV_8UC3);

 vector<vector<Point> > contours;
 vector<Vec4i> hierarchy;    

 findContours( imageIn, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
 for( int idx = 0; idx >= 0; idx = hierarchy[idx][0] )
 {
     Scalar color( rand()&255, rand()&255, rand()&255 );
     drawContours( imageOut, contours, idx, color, CV_FILLED, 8, hierarchy );
 }

It should draw the walls in different colors. If it works, that means that in "hierarchy" each wall is identified as a contour, you then will have to find out which one the user selected on his touch screen and do your color tuning processing.

You may have to change the different parameters in "findContours" link. You will also need to smooth the input image before the contour detection to avoid being annoyed with the details or textures.

Hope that helps, Thomas