-
-
Couldn't load subscription status.
- Fork 1.2k
Closed
Labels
Description
Summary of your issue
when i use the mat from the Mat mm = new Mat(string path) , i draw Rect or Line on this mat using Cv2.Rectangle() and Cv2.Line(), the result is show normally.
but, when i use the mat from OpenCvSharp.Extensions.BitmapConverter.ToMat(Bitmap bitmap), No matter how I change the scalar , the results of drawing is abnormal ,
i show the results in the picturebox , it just like using the scalar.white no matter what scalar i have chosed.
Environment
vs2019, opencvsharp4 4.5.5.20211231
Example code:
private void button1_Click(object sender, EventArgs e)
{
string path = @"E:\myPictures\LenaSource\lena_JPG.jpg";
pictureBox1.Image = new Bitmap(path);
pictureBox2.Image = new Bitmap(path);
Mat mm = new Mat(path);
Bitmap bitmap = new Bitmap(pictureBox2.Image);
Mat mm2 = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
OpenCvSharp.Rect rect = new Rect(50, 50, 100, 100);
Cv2.Rectangle(mm, rect, Scalar.Red, 1, LineTypes.AntiAlias);
Cv2.Rectangle(mm2, rect, Scalar.Red, 1, LineTypes.AntiAlias);
//Cv2.Line(mm, 50, 50, 150, 50, Scalar.Red);
//Cv2.Line(mm, 50, 50, 50, 150, Scalar.Red);
//Cv2.Line(mm, 150, 50, 150, 150, Scalar.Red);
//Cv2.Line(mm, 150, 150, 50, 150, Scalar.Red);
//Cv2.Line(mm2, 50, 50, 150, 50, Scalar.Red);
//Cv2.Line(mm2, 50, 50, 50, 150, Scalar.Red);
//Cv2.Line(mm2, 150, 50, 150, 150, Scalar.Red);
//Cv2.Line(mm2, 150, 150, 50, 150, Scalar.Red);
pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mm);
pictureBox2.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mm2);
}
Output:
What did you intend to be?
the results of using the mat from OpenCvSharp.Extensions.BitmapConverter.ToMat(Bitmap bitmap) is different from the results of using the mat from new mat(string path).
the results of using Cv2.Rectangle() is also different from the results of using Cv2.Line() where the mat is from OpenCvSharp.Extensions.BitmapConverter.ToMat(Bitmap bitmap).
in theory , they should be the same.
I wonder what went wrong in the process of my use.
And, How to use the mat from OpenCvSharp.Extensions.BitmapConverter.ToMat(Bitmap bitmap) correctly to draw rect and lines.

