Closed yan97xh closed 1 year ago
Could you tell me the depth/channels of bitmap
and mm2
?
My expectation is that bitmap.PixelFormat
is PixelFormat.Format32bppRgb
and mm2.Type
is 8UC4
. new Bitmap(file)
will usually create a PixelFormat.Format32bppRgb Bitmap.
Cv2.Line and Cv2.Rectangle should work as expected for 8UC3 (BGR) Mat, but should have unintended results for 8UC4 Mat.
You may be able to work around this problem by doing the following:
Bitmap bitmap = new Bitmap(pictureBox2.Image);
using Mat mm2 = new Mat(bitmap.Height, bitmap.Width, MatType.CV_8UC3);
OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap, mm2);
thanks, I used your method to solve the problem。
i checked the mm2.Type is 8UC4 , but , i use the mm2.ConvertTo(mm2, MatType.CV_8UC3) ,it doesn't work, the result is still 8UC4. i use the Cv2.CvtColor(mm2, mm2, ColorConversionCodes.BGRA2BGR), the result is changed to 8UC3
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Summary of your issue
Environment
vs2019, opencvsharp4 4.5.5.20211231
Example code:
Output:
using the Cv2.Rectangle()
using the Cv2.Line()
What did you intend to be?