Guest User

Untitled

a guest
Jan 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. struct BufferPSNR                                     // Optimized GPU versions
  2. {   // Data allocations are very expensive on GPU. Use a buffer to solve: allocate once reuse later.
  3.     gpu::GpuMat gI1, gI2, gs, t1,t2;
  4.  
  5.     gpu::GpuMat buf;
  6. };
  7.  
  8. double getPSNR_GPU(const Mat& I1, const Mat& I2)
  9. {
  10.     gpu::GpuMat gI1, gI2, gs, t1,t2;
  11.  
  12.     gI1.upload(I1);
  13.     gI2.upload(I2);
  14.  
  15.     gI1.convertTo(t1, CV_32F);
  16.     gI2.convertTo(t2, CV_32F);
  17.  
  18.     gpu::absdiff(t1.reshape(1), t2.reshape(1), gs);
  19.     gpu::multiply(gs, gs, gs);
  20.  
  21.     Scalar s = gpu::sum(gs);
  22.     double sse = s.val[0] + s.val[1] + s.val[2];
  23.  
  24.     if( sse <= 1e-10) // for small values return zero
  25.         return 0;
  26.     else
  27.     {
  28.         double  mse =sse /(double)(gI1.channels() * I1.total());
  29.         double psnr = 10.0*log10((255*255)/mse);
  30.         return psnr;
  31.     }
  32. }
Add Comment
Please, Sign In to add comment