网络流中的图像转化为OpenCV中的Mat类型

时间:2023-12-19 11:40:56

1,从网络中读取到的图像流,不支持查找,不能直接转化为Mat类型

2,例子如下:

string Url = "http://192.168.0.110/cgi-bin/camera?resolution=1920";                           //网络地址
            Stream stream = WebRequest.Create(Url).GetResponse().GetResponseStream();   //获取到网络流
            Bitmap bmp = new Bitmap(stream);                                                                             //从流中获取Bitmap
            MemoryStream ms = new MemoryStream();                                                               //申请内存流
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);                                    //将获得到的Bitmap保存到内存流中(关键技术)
            Mat scr = Mat.FromStream(ms, ImreadModes.AnyColor);                                           //从内存流中获取Mat对象。