Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 1st, 2012  |  syntax: None  |  size: 0.62 KB  |  hits: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Implement radial blur with OpenCV
  2. float center_x = width/2; //or whatever
  3. float center_y = height/2;
  4. float blur = 0.02; //blur radius per pixels from center. 2px blur at 100px from center
  5. int iterations = 5;
  6.  
  7. Mat mapx, mapy;
  8. for(int x = 0; x < width; x++) {
  9.    for(int y = 0; y < height; y++) {
  10.        mapx[x,y] = (x - center_x)/blur;
  11.        mapy[x,y] = (y - center_y)/blur;
  12.    }
  13. }
  14.  
  15. Mat tmp1, tmp2;
  16. for(int i = 0; i < iterations; i++)  {
  17.     remap(src, tmp1, mapx, mapy, CV_INTER_LINEAR); // enlarge
  18.     remap(src, tmp2, -mapx, -mapy, CV_INTER_LINEAR); // shrink
  19.     addWeighted(tmp1, 0.5, tmp2, 0.5, 0, src); // blend back to src
  20. }