如何在EmguCV中将Bitmap转换为Mat结构以及如何检测两个图像的移位

Mar*_*usz 10 c# opencv bitmap image-processing emgucv

亲爱的论坛会员们,您好!

我正在开发一个项目来检测安全摄像头的更改视图.我的意思是,当有人试图移动相机(某种破坏......)时我必须注意到这一点.我的想法是:

  • 每隔10秒从相机中捕捉图像并比较这两张图片(旧图片和实际图片).

我需要控制近70台摄像机,所以我不能使用实时流媒体,因为它可能会占用我的互联网连接.我使用Emgu CV库来完成这项任务,但是在我工作期间我遇到了一些问题..这里是我编写的代码:

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,我有两个问题:

  1. 如何将Bitmap转换为Mat结构.

目前我根据文件路径读取我的图像以从光盘进行比较.但我想发送比较收集的位图而不保存在我的硬盘上.

  1. 你知道另一种检测两张照片之间转换的方法吗?我非常感谢这方面的任何其他建议.

问候,

马里乌什

小智 18

我知道很晚才回答这个问题,但今天我在互联网上寻找这个问题,我发现这样的事情:

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
Run Code Online (Sandbox Code Playgroud)