luhfluh
luhfluh

Reputation: 484

Opencv Sobel edge detection for diagonal (up-right 45deg, upleft 135deg)

I am having issue with opencv's Sobel edge detector. From its documentation it seems to work only for horizontal and vertical direction edges (by specifying 0,1 or 1,0). Has anyone got idea how to get the diagonal edges 45deg and 135deg with cvSobel (not Canny methods). Matlab has a soultion with its edge(I,'sobel' ...) option, but my code is all in c++ and I would like to keep it as such.

Thanks for suggestions and solutions.

Upvotes: 4

Views: 4618

Answers (2)

john k
john k

Reputation: 6615

It does detect diagonals. You just run it twice. A point that is both horizontal and vertical is, by definition, diagonal.

Upvotes: 0

DanielHsH
DanielHsH

Reputation: 4453

Hei. You can generally calculate any filter in any direction in the following way:

  1. resX = Calculate result on X direction
  2. resY = Caluclate result on Y direction
  3. Choose desired direction (angle alpha)
  4. The desired result is sqrt((Y*sin(alpha))^2 + (X*cos(alpha))^2)

This works for edge detection, motion blur and any linear directed filter.

Upvotes: 5

Related Questions