Reputation: 1963
Well this is a layman's attempt on blurring an image, i am not using any specific [already known] alogrithm, i am implementing my own technique.
float k[][5]= { .01, .01, .01, .01, .01,
.01, .01, .01, .01, .01,
.01, .01, .01, .01, .01};
for( row = 0; row < rows; ++row)
{
sum=0;
for ( col = 0; col < cols; ++col)
{
temp_ptr = &((uchar*)(img->imageData + (img->widthStep*row)))[col];
for( i=1; i<6;i++)
{
float factor=exp((float)(-(i-col)*(i-col)/(2*sigma2)));
sum+=factor;
for( j=1; j<6 ;j++)
{
if( (row-j)>0 && (col-i)>0 )
k[i-1][j-1]+=factor*temp_ptr[row-i+col-j];
}
for( j=1; j<6 ;j++)
{
if( (row-j)>0 && (col-i)>0 )
{
uchar* temp_ptr1 = &((uchar*)(img->imageData + (img->widthStep * (row-1) )))[col-1];
temp_ptr1[0]=temp_ptr[0]*k[i-1][j-1]/sum;
temp_ptr1[1]=temp_ptr[1]*k[i-1][j-1]/sum;
temp_ptr1[2]=temp_ptr[2]*k[i-1][j-1]/sum;
}
}
}
}
}
Upvotes: 0
Views: 176
Reputation: 197
Your j
index is out of bound for array k
.
It can not be greater than 5 !
In 5th for
you should change upper bound to 5
not 6
.
Upvotes: 1
Reputation: 52407
I don't know, but the code is very error-prone. Use the C++ interface to OpenCV.
Upvotes: 0
Reputation: 96311
k
only has three rows and yet you're accessing nonexistent rows 4 and 5 in your first inner j
for
loop. After you access those rows all bets are off for the rest of your program.
Upvotes: 0