Ask Your Question

Revision history [back]

faster X/Y matrix creation

Hi!

Is there more efficient way in OpenCV to create a MxN CV_32FC2 matrix than this?

  // create XY 2D array
  // (((0, 0), (1, 0), (2, 0), ...),
  //  ((0, 1), (1, 1), (2, 1), ...),
  // ...)
  cv::Mat xy(img_size, CV_32FC2);
  float *pxy = (float*)xy.data;
  for (int y = 0; y < img_size.height; y++)
    for (int x = 0; x < img_size.width; x++)
    {
      *pxy++ = x;
      *pxy++ = y;
    }

I need it as a base for cv::perspectiveTransform() (see this post). Any speedup is welcome.

Thanks.