Reputation: 43
I am new to EmguCV
and trying to do a simple task; instantiate a Mat
using an existing one. 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. I also tried a gray image (3 changed to 1) with the same result.
Any suggestions that I am doing something wrong?
Upvotes: 1
Views: 1803
Reputation: 3744
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. Instead, it just initializes the matrix header that points to the specified data, which means that no data is copied.
If you want to create a new Mat
with the date of the old one, you can use this:
Mat color2 = new Mat();
color.CopyTo(color2);
Upvotes: 3