Different cv::Mat after calling the same method and arguments?

asked 2017-04-01 18:12:53 -0600

lovaj gravatar image

updated 2017-04-01 18:13:27 -0600

I have this code:

vector<Mat> blurs (par.numberOfScales+3, Mat());
vector<float> sigmas(par.numberOfScales+3);
//fill blurs and sigmas someway
...
Mat high = hessianResponse(blurs[i+1], sigmas[i+1]*sigmas[i+1]);
Mat comp = hessianResponse(blurs[i+1], sigmas[i+1]*sigmas[i+1]);
equalMats(high, comp);
...

Where:

void equalMats(const Mat &a, const Mat &b){
    cv::Mat diff;
    cv::bitwise_xor(a, b, diff);
    // Equal if no elements disagree
    assert( cv::countNonZero(diff) == 0);
}

And (taken from here):

Mat HessianDetector::hessianResponse(const Mat &inputImage, const float norm)
{
   const int rows = inputImage.rows;
   const int cols = inputImage.cols;
   const int stride = cols;

   // allocate output
   Mat outputImage(rows, cols, CV_32FC1);

   // setup input and output pointer to be centered at 1,0 and 1,1 resp.
   const float *in = inputImage.ptr<float>(1);
   float      *out = outputImage.ptr<float>(1) + 1;

   float norm2 = norm * norm;

   /* move 3x3 window and convolve */
   for (int r = 1; r < rows - 1; ++r)
   {
      float v11, v12, v21, v22, v31, v32;      
      /* fill in shift registers at the beginning of the row */
      v11 = in[-stride]; v12 = in[1 - stride];
      v21 = in[      0]; v22 = in[1         ];
      v31 = in[+stride]; v32 = in[1 + stride];
      /* move input pointer to (1,2) of the 3x3 square */
      in += 2;
      for (int c = 1; c < cols - 1; ++c)
      {
         /* fetch remaining values (last column) */
         const float v13 = in[-stride];
         const float v23 = *in;
         const float v33 = in[+stride];

         // compute 3x3 Hessian values from symmetric differences.
         float Lxx = (v21 - 2*v22 + v23);
         float Lyy = (v12 - 2*v22 + v32);
         float Lxy = (v13 - v11 + v31 - v33)/4.0f;

         /* normalize and write out */
         *out = (Lxx * Lyy - Lxy * Lxy)*norm2;

         /* move window */
         v11=v12; v12=v13;
         v21=v22; v22=v23;
         v31=v32; v32=v33;

         /* move input/output pointers */
         in++; out++;
      }
      out += 2;
   }
   return outputImage;
   }

If you want to see full hessianResponse's implementation, see here.

Now, for some reason, equalMats fails (so high and comp are different). A subset of different values:

a(0,652)=11.7962 b(0,652)=0
a(0,653)=13.2172 b(0,653)=0
a(0,654)=14.4621 b(0,654)=0
a(0,655)=15.4783 b(0,655)=0
a(0,656)=16.2395 b(0,656)=0
a(0,657)=16.7433 b(0,657)=0
a(0,658)=17.0053 b(0,658)=0
a(0,659)=17.0513 b(0,659)=0
a(0,660)=16.9105 b(0,660)=0
a(0,661)=16.6106 b(0,661)=0
a(0,662)=16.1759 b(0,662)=0
a(0,663)=15.6269 b(0,663)=0
a(0,664)=14.9816 b(0,664)=0
a(0,665)=14.2563 b(0,665)=0
a(0,666)=13.4675 b(0,666)=0
a(0,667)=12.6334 b(0,667)=0
a(0,668)=11.7744 b(0,668)=0
a(0,669)=10.9132 b(0,669)=0
a(0,670)=10.0744 b(0,670)=0
a(0,671)=9.28306 b(0,671 ...
(more)
edit retag flag offensive close merge delete