我找到的一些答案建议使用:
frame = ...
Rectangle ROI = ...
Mat crop = new Mat(frame, ROI)
但这在Emgu 3.x中似乎无法工作
Ahmed,您不必创建一个 Image<> 就可以创建一个 Mat。请尝试以下操作:
Mat myNewMat = new Mat(input, crop_region);
由于您没有旋转矩形,因此无需将旋转矩形转换为正常矩形。 因此,您只需从现有的Mat和矩形创建一个新的Mat即可。
这应该可以工作,并且可以简化您的代码。
Doug
Mat crop_color_frame(Mat input, Rectangle crop_region)
{
/*
* TODO(Ahmed): Figure out why I had to copy this into this class.
* */
Image<Bgr, Byte> buffer_im = input.ToImage<Bgr, Byte>();
buffer_im.ROI = crop_region;
Image<Bgr, Byte> cropped_im = buffer_im.Copy();
return cropped_im.Mat;
}