mobearette
mobearette

Reputation: 397

Segfault when using open cv Mat::at

I am trying to fill out a opencv matrix with some values, but I keep getting segfaults. The code is following:

Mat mask_gx(in_window_size, in_window_size, image.type());
  for(int i = 0; i <= in_window_size; i++)
  {
    for(int j = 0; j <= in_window_size; j++)
    {
      double gx = (-i/in_sigma) * pow(M_E, ((pow(i, 2)* pow(j, 2))/pow(in_sigma, 2))/(-2));
      mask_gx.at<double>(j, i) = gx;
    }
  }

The problem is in the last line. I have tested it with:

mask_gx.at<int>(j, i) = 1;

and I still get the segfault.

Does anyone have any ideas what seems to be the problem with this code?

Upvotes: 2

Views: 3945

Answers (1)

Victor Zamanian
Victor Zamanian

Reputation: 3180

If in_window_size is the amount of values in each dimension, then it should be < and not <= in the for-loop comparisons, I believe.

Upvotes: 1

Related Questions