简体   繁体   English

EmguCV 如何使用现有的垫子创建垫子?

[英]EmguCV How to create a Mat using an existing Mat?

I am new to EmguCV and trying to do a simple task;我是EmguCV的新手,正在尝试做一个简单的任务; instantiate a Mat using an existing one.使用现有的 Mat 实例化一个Mat Here is the code snippet:这是代码片段:

Mat color = CvInoke.Imread("000.bmp"); //512x512 3 channel image
Mat color2 = new Mat(512, 512, Emgu.CV.CvEnum.DepthType.Cv8U, 3, color.Ptr, 512 * 3);
CvInvoke.Imshow("Color2", color2);
CvInvoke.WaitKey(0);

It shows a corrupted image.它显示损坏的图像。 It seems like the step and channel parameter are not correct.似乎 step 和 channel 参数不正确。 I also tried a gray image (3 changed to 1) with the same result.我还尝试了具有相同结果的灰色图像(3 更改为 1)。

Any suggestions that I am doing something wrong?有什么建议我做错了吗?

According to EmguCV Documentation , this command doesn't copy the source Mat to the target Mat , it only Create a Mat header from existing data , also it does not allocate matrix data.根据EmguCV Documentation ,此命令不会将源Mat复制到目标Mat ,它仅Create a Mat header from existing data也不分配矩阵数据。 Instead, it just initializes the matrix header that points to the specified data, which means that no data is copied.相反,它只是初始化了指向指定数据的矩阵 header,这意味着没有数据被复制。

If you want to create a new Mat with the date of the old one, you can use this:如果你想用旧的日期创建一个新的Mat ,你可以使用这个:

Mat color2 = new Mat();        
color.CopyTo(color2);

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

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