如何将Mat复制到ROI?

时间:2013-04-01 13:49:47

标签: c++ opencv

我是OpenCV的新手,我正在尝试使用OpenCV将像素缓冲区复制到屏幕的一部分。

我这样做:

//In the beginning I allocate the screen buffer and create a Mat for it
void initScreen(int screenWidth, int screenHeight) {

      pixels = new uint8_t[screenWidth*screenHeight*BITS_PER_PIXEL];
      screenMat = new Map(Size(screenWidth, screenHeight), PIXEL_FORMAT);
      screenMat->data = pixels
}

// Here I'm getting the pixel data to display on screen and coords where they should be displayed
void onDisplayPixels(int l, int t, int w, int h, void* newPixels) 
{
      // So I set a ROI at my screen Map
      Mat roi(screenMat, cv::Rect(l, t, w, h));

      // And I create a new Mat for the new pixels 
      Mat newPixelsMat(Size(w, h), newPixels, PIXELS_FMT);


      // Now I need to copy newPixelsMat to roi 
      **But how do I do that??**
}

1 个答案:

答案 0 :(得分:2)

只需像这样使用Mat::copyTo()

newPixelsMat.copyTo(roi);