简体   繁体   English

在Emgu.CV中裁剪图像

[英]Crop Image in Emgu.CV

I have ROI of the image and I need to create new image that would be subpart of image. 我有图像的投资回报率,我需要创建新图像作为图像的一部分。 How can I do that? 我怎样才能做到这一点? (I want to make pieces an array of images, not rectangles.) (我想将图像组成一个数组,而不是矩形。)

Image<Bgr, byte> img = frame.Copy();
pieces = new List<System.Drawing.Rectangle>();

int input_cell_width = img.Width / Cols;
int input_cell_height = img.Height / Rows;

System.Drawing.Rectangle old_roi = img.ROI;

for (int row = 0; row < Rows; ++row)
{
    for (int col = 0; col < Cols; ++col)
    {
        // Get template
        img.ROI = gridOuput.GetCellItemRect(row, col, new System.Drawing.Point(0, 0));
        pieces.Add(img.ROI);
    } 
}

Thanks. 谢谢。

First set the image's ROI (as you already do) and then use the Copy() member method of Image. 首先设置图像的ROI(如您已经做的那样),然后使用Image的Copy()成员方法。 As long as an image's ROI is set, Copy() will only copy that subpart of the image. 只要设置了图像的ROI,Copy()将仅复制图像的该子部分。 See the example below. 请参见下面的示例。

var rois = new List<Rectangle>(); // List of rois
var imageparts = new List<Image<Gray,byte>>(); // List of extracted image parts

using (var image = new Image<Gray, byte>(...))
{
    foreach (var roi in rois)
    {
        image.ROI = roi;
        imageparts.Add(image.Copy());   
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM