How to convert bitmap to Mat structur in EmguCV and how to detect two image offsets

Hello, dear forum members!

I am working on a project to detect the kind of change from a security camera. I mean, when someone tries to move the camera (some kind of sabotage), I have to notice it. My idea:

  • Capture camera images every 10 seconds and compare these two photos (old and actual images).

There are almost 70 cameras that I need to control, so I can’t use the live broadcast, because it can take my Internet connection. I use the Emgu CV library to accomplish this task, but during my work I ran into some kind of problem. Here is the part of the code that 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 a Bitmap structure to Mat.

I am currently reading my images for comparison with the disk according to the file path. But I would like to send for comparison a collection of raster images without saving to my hard drive.

  1. Do you know any other way to detect a shift between two pictures ?. I would be very grateful for any other suggestion in this area.

Hello,

Mariusz

+6
source share
1 answer

I know it is very late to answer this, but today I searched for this problem on 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 
+10
source

Source: https://habr.com/ru/post/979070/


All Articles