
Untitled
By: a guest on
Jun 1st, 2012 | syntax:
None | size: 0.62 KB | hits: 50 | expires: Never
Implement radial blur with OpenCV
float center_x = width/2; //or whatever
float center_y = height/2;
float blur = 0.02; //blur radius per pixels from center. 2px blur at 100px from center
int iterations = 5;
Mat mapx, mapy;
for(int x = 0; x < width; x++) {
for(int y = 0; y < height; y++) {
mapx[x,y] = (x - center_x)/blur;
mapy[x,y] = (y - center_y)/blur;
}
}
Mat tmp1, tmp2;
for(int i = 0; i < iterations; i++) {
remap(src, tmp1, mapx, mapy, CV_INTER_LINEAR); // enlarge
remap(src, tmp2, -mapx, -mapy, CV_INTER_LINEAR); // shrink
addWeighted(tmp1, 0.5, tmp2, 0.5, 0, src); // blend back to src
}