Ask Your Question
0

how to calculate gradient in c++ using Opencv?

asked 2017-03-29 03:37:22 -0600

kean gravatar image

updated 2017-03-29 03:58:19 -0600

Dear guys
I'm new in opencv, I'm looking for a simple method to find out how to calculate gradient of an image for sobel filter.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-03-30 01:37:25 -0600

berak gravatar image

the question might be a bit unclear, but i guess, you wanted the gradient, as in : "angles" and "magnitude", which might be achieved using 2 Sobel calls and cartToPolar

Mat img = ...
cvtColor(img, img, COLOR_BGR2GRAY);

Mat dx, dy; // 1st derivative in x,y
Sobel(img, dx, CV_32F, 1,0);
Sobel(img, dx, CV_32F, 0,1);

Mat angle, mag;
cartToPolar(dx, dy, mag, angle);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-03-29 03:37:22 -0600

Seen: 3,637 times

Last updated: Mar 30 '17