Reputation: 1769
I wrote the following code to load a picture with any type, I convert it to type CV_8UC1 and then save it again in the file.
The problem is that when I load the saved image it is not a CV_8UC1 type but a CV_8UC3 type.
Where am I wrong?
private void SaveTest()
{
var fileName = @"F:\src.png";
Mat src = new Mat(fileName);
var gray = src.CvtColor(ColorConversionCodes.BGR2GRAY);
Debug.Assert(gray.Type() == MatType.CV_8UC1);
var fileName2 = @"F:\temp.png";
gray.ImWrite(fileName2);
Mat test = new Mat(fileName2);
Debug.Assert(test.Type() == MatType.CV_8UC1);
}
Upvotes: 0
Views: 4447
Reputation: 1769
Just change instead this:
Mat test = new Mat(fileName2);
this:
Mat test = new Mat(fileName2, ImreadModes.Unchanged);
Upvotes: 1