①openCVsharp 调用2个摄像头读取图像
②倒计时触发保存图像
③保存时会提示对象被占用无法使用问题private void CaptureRead(VideoCapture capture, PictureBox picture,ENM_CAPTURE eNM_CAPTURE)
{
//首先定义face_token表示为空
//人脸检测
using (Mat frame = new Mat())
{
int i = 0;
while (!canel)
{
try
{
if (!capture.IsOpened()) capture.Open((int)eNM_CAPTURE); //读取图片信息
if (capture.Read(frame))
{
if (frame.Empty()) return; picture.Image = Image.FromStream(new MemoryStream(frame.ToBytes()));
Thread.Sleep(60); i++;
}
}
catch (Exception ex)
{
baseLogger.Error(ex.Message);
continue;
}
}
}
}
using (var img = pictureBox2.Image)
{
M_IMG iMG1 = new M_IMG();
iMG1.im_name = $"{montion.id}_F_{_SN.sn}.jpg";
iMG1.im_base64 = ImageBase64(img);
_SN.images.Add(iMG1);
}
using (var img = pictureBox3.Image)
{
M_IMG iMG2 = new M_IMG(); iMG2.im_name = $"{montion.id}_S_{_SN.sn}.jpg";
iMG2.im_base64 = ImageBase64(img);
_SN.images.Add(iMG2);
}
private string ImageBase64(Image img)
{
byte[] arr = null;
try
{
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(arr, 0, (int)ms.Length);
ms.Close();
}
}
catch (Exception ex)
{
baseLogger.Error(ex.Message);
AutoClosingMessageBox.Show(ex.Message, "错误", 3000);
}
return Convert.ToBase64String(arr);
}
②倒计时触发保存图像
③保存时会提示对象被占用无法使用问题private void CaptureRead(VideoCapture capture, PictureBox picture,ENM_CAPTURE eNM_CAPTURE)
{
//首先定义face_token表示为空
//人脸检测
using (Mat frame = new Mat())
{
int i = 0;
while (!canel)
{
try
{
if (!capture.IsOpened()) capture.Open((int)eNM_CAPTURE); //读取图片信息
if (capture.Read(frame))
{
if (frame.Empty()) return; picture.Image = Image.FromStream(new MemoryStream(frame.ToBytes()));
Thread.Sleep(60); i++;
}
}
catch (Exception ex)
{
baseLogger.Error(ex.Message);
continue;
}
}
}
}
using (var img = pictureBox2.Image)
{
M_IMG iMG1 = new M_IMG();
iMG1.im_name = $"{montion.id}_F_{_SN.sn}.jpg";
iMG1.im_base64 = ImageBase64(img);
_SN.images.Add(iMG1);
}
using (var img = pictureBox3.Image)
{
M_IMG iMG2 = new M_IMG(); iMG2.im_name = $"{montion.id}_S_{_SN.sn}.jpg";
iMG2.im_base64 = ImageBase64(img);
_SN.images.Add(iMG2);
}
private string ImageBase64(Image img)
{
byte[] arr = null;
try
{
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(arr, 0, (int)ms.Length);
ms.Close();
}
}
catch (Exception ex)
{
baseLogger.Error(ex.Message);
AutoClosingMessageBox.Show(ex.Message, "错误", 3000);
}
return Convert.ToBase64String(arr);
}
解决方案 »
- timeSpan
- 如何获得图片的正确格式
- DataTable 数据复制到数据库
- winfrom做IE,如果做到点击IE中的按钮最小化winfrom窗体?
- udp获取远程端口
- 函数传参问题,急
- gridview 里 dataformatstring 怎么设置才能让日期型字段 在gridview里 只显示年??
- 各位老大:怎么解决发送C#发送Email附件的问题啊?拜托了!我找不出来原因啊!!求救!!
- 帮帮忙,有没有关于部署方面的资料,提供一下
- 怎么用C#调用sql server中的DTS包啊??
- ref参数用于异步线程
- VS2019 C#开发,在主窗体中加入UDP 端点初始化进不了调试状态,请指点!
解决方法:(以下是我在WPF中的解决方法,你根据自身情况解决)读取流之后,对流对象进行一次Clone,然后,用复本赋值界面控件: Image image = Image.FromFile(x.FullName);
Image x1 = (Image)(image.Clone());image.Dispose();//释放原始文件//之后使用x1进行操作,完成之后,对x1进行释放,如我在WPF中使用的所示