# Sobel operator gives too large values

I've applied Sobel operator to my image and obtained very large values (e.g 1347440720, -1970897035, ...). Is it normal? Should I scale it using convertScaleAbs( grad_x, abs_grad_x )? My snippet of code is here. What is more interesting minmaxLoc gives uninterpretable values too. Help me please with this case.

int scale = 1;
int delta = 0;
int ddepth = CV_16S;
Sobel(prev_frame, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT );
Sobel(prev_frame, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT );

Mat diff = frame - prev_frame;
double min, max;
cout << min << endl;
cout << max << endl;

for (int i = 0; i < grad_x.cols; i++)
{
for (int j = 0; j < grad_x.rows; j++)
{
cout << grad_x.at<int>(i, j) << endl;
}
}

OUTPUT:

51968
65523
0
0
0
.
.
.
1532713819
1532713819
edit retag close merge delete

Sort by ยป oldest newest most voted

CV_16S means signed short this line is wrong, also you got i,j wrong.

(opencv is row-major)

cout << grad_x.at<int>(i, j) << endl;

It should be

I use this program to test ( frame unused) grad_x empty don't need to print....

{
resize(prev_frame, prev_frame, Size(8, 8));
cout << prev_frame << " \n";
int scale = 1;
int delta = 0;
int ddepth = CV_16S;
Sobel(prev_frame, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT);
Sobel(prev_frame, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT);

double min, max;
cout << min << endl;
cout << max << endl;

for (int j = 0; j < grad_x.rows; j++)
{
for (int i = 0; i < grad_x.cols; i++)
{
}
cout << endl;
}*/
}
more

minMaxLoc result still look weird

( 2018-02-03 14:28:01 -0600 )edit

Official site

GitHub

Wiki

Documentation