How to convert Bitmap to Mat structur in EmguCV & How to detect two images shift
I know its very late to answer this but today I was looking for this problem in the internet and I found something like this:
Bitmap bitmap; //This is your bitmap
Image<Bgr, byte> imageCV = new Image<Bgr, byte>(bitmap); //Image Class from Emgu.CV
Mat mat = imageCV.Mat; //This is your Image converted to Mat
Mariusz
Updated on June 05, 2022Comments
-
Mariusz almost 2 years
Hello Dear Forum Members !
I am working on a project to detect change view from security camera. I mean, when someone try to move camera (some kind of sabotage...) I have to notice this. My idea is:
- capture images from camera every 10 sec and compare this two pictures ( Old and actual picture).
There are almost 70 cameras which I need to control, so I can't use live streaming because it could occupy my internet connection. I use Emgu CV library to make this task, but during my work I stuck with some problem.. Here im piece of my code what I prepared:
public class EmguCV { static public Model Test(string BaseImagePath, string ActualImagePath) { double noise = 0; Mat curr64f = new Mat(); Mat prev64f = new Mat(); Mat hann = new Mat(); Mat src1 = CvInvoke.Imread(BaseImagePath, 0); Mat src2 = CvInvoke.Imread(ActualImagePath, 0); Size size = new Size(50, 50); src1.ConvertTo(prev64f, Emgu.CV.CvEnum.DepthType.Cv64F); src2.ConvertTo(curr64f, Emgu.CV.CvEnum.DepthType.Cv64F); CvInvoke.CreateHanningWindow(hann, src1.Size, Emgu.CV.CvEnum.DepthType.Cv64F); MCvPoint2D64f shift = CvInvoke.PhaseCorrelate(curr64f, prev64f, hann, out noise ); double value = noise ; double radius = Math.Sqrt(shift.X * shift.X + shift.Y * shift.Y); Model Test = new Model() { osX = shift.X, osY = shift.Y, noise = value }; return Test; } }
Therefore, I have two questions:
- How to convert Bitmap to Mat structure.
At the moment I read my images to compare from disc according to file path. But I would like to send to compare collection of bitmaps without saving on my hard drive.
- Do you know any another way to detect shift between two pictures ?. I would be really grateful for any other suggestion in this area.
Regards,
Mariusz
-
silentsod over 7 yearsWelcome to StackOverflow, you may want to clean up your answer by editing it and converting the code snippet you've included to a code block by selecting the lines and clicking on the curly braces {} icon.
-
Rey over 7 yearsI didn't know that, this is the first time I post. Thanks
-
Võ Quang Hòa over 4 yearsIt's still very useful. Thanks for saving my time.