Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Bitmap to Mat structur in EmguCV & How to detect two images shift

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:

  1. 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.

  1. 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

like image 923
Mariusz Avatar asked Dec 03 '14 20:12

Mariusz


1 Answers

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
like image 195
Rey Avatar answered Oct 23 '22 19:10

Rey