Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How detect long edges of wall to prepare mask and recolor

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

like image 571
Jigar Parekh Avatar asked Apr 19 '13 08:04

Jigar Parekh


People also ask

What is mask in edge detection?

Kirsch Compass Mask is also a derivative mask which is used for finding edges. Kirsch mask is also used for calculating edges in all the directions.

What are various masks to detect edges in an image?

Here are some of the masks for edge detection. Prewitt Operator • Sobel Operator • Robinson Compass Masks • Kirsch Compass Masks • Laplacian Operator.

What are the filters used for edge detection?

The Canny filter is a multi-stage edge detector. It uses a filter based on the derivative of a Gaussian in order to compute the intensity of the gradients. The Gaussian reduces the effect of noise present in the image.


1 Answers

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

like image 157
Thom Avatar answered Oct 23 '22 09:10

Thom