Ehsan Akbar
Ehsan Akbar

Reputation: 7299

Apply sobel filter for edge detection in emgucv

I am trying to apply Sobel filter on my picture to detect edges as you can see here :

Image<Gray, Byte> imgProcessed1;
private void Form1_Load(object sender, EventArgs e)
{



    Image<Bgr, Byte> imgProcessed=new Image<Bgr, byte>(@"C:\Users\Public\Pictures\Sample Pictures\1.jpg");

    imgProcessed1 = imgProcessed.Convert<Gray, byte>();
    Image<Gray, Single> img_final = (imgProcessed1.Sobel(1, 0, 5));
    pictureBox1.Image = img_final.ToBitmap();
}

but the result is very unusual ,i am so new in opencv.

my output

enter image description here

I need this result.

enter image description here

i just need to apply this filter

enter image description here

Upvotes: 1

Views: 11511

Answers (2)

Ehsan Akbar
Ehsan Akbar

Reputation: 7299

thank you all my friend ,i finally found a solution :

Image<Gray, byte> gray = new Image<Gray, byte>(@"C:\Users\Public\Pictures\Sample Pictures\1.jpg");
            Image<Gray, float> sobel = gray.Sobel(0, 1, 3).Add(gray.Sobel(1, 0, 3)).AbsDiff(new Gray(0.0));
            pictureBox1.Image = sobel.ToBitmap();

Upvotes: 7

Dvir
Dvir

Reputation: 3139

According to opencv documentation:

http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.html

you should use the sobel operator in the following way:

Sobel( src_gray, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT );

The function takes the following arguments:

  1. src_gray: In our example, the input image. Here it is CV_8U
  2. grad_x/grad_y: The output image.
  3. ddepth: The depth of the output image. We set it to CV_16S to avoid overflow.
  4. x_order: The order of the derivative in x direction.
  5. y_order: The order of the derivative in y direction.
  6. scale, delta and BORDER_DEFAULT: We use default values.

I hope it support you question.

Upvotes: 2

Related Questions