Skip to content

Instantly share code, notes, and snippets.

@fernandoc1
Created September 24, 2019 21:53
Show Gist options
  • Save fernandoc1/e69e4c09d0bf4b09076af40c06b13450 to your computer and use it in GitHub Desktop.
Save fernandoc1/e69e4c09d0bf4b09076af40c06b13450 to your computer and use it in GitHub Desktop.
This extracts a ROI from images that are 16bits per pixel.
void extractRoi(cv::Mat& inImage, cv::Mat& outImage, cv::Rect roi)
{
/* Create the image */
outImage = cv::Mat(roi.height, roi.width, inImage.type());
/* Populate the image */
for (int i = roi.y; i < (roi.y+roi.height); i++)
{
uint16_t* inP = inImage.ptr<uint16_t>(i);
uint16_t* outP = outImage.ptr<uint16_t>(i-roi.y);
for (int j = roi.x; j < (roi.x+roi.width); j++)
{
outP[j-roi.x] = inP[j];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment