C#借助OpenCvSharp读取摄像头并显示的实现示例
作者:AI小白龙 时间:2022-12-22 05:49:51
1,首先要安装OpenCvSharp,使用cv2的函数获取设备,并将图像转换到Bitmap
using OpenCvSharp;
using OpenCvSharp.Extensions;
void run_cap()
{
Mat src = new Mat();
FrameSource frame = Cv2.CreateFrameSource_Camera(0);
while (f1)
{
frame.NextFrame(src);
Bitmap bitmap = BitmapConverter.ToBitmap(src);
Invalidate();
pictureBox1.Invalidate();
imgshow = bitmap;
}
}
2,在调用时开启线程,可以在主函数内调用,也可在按钮内调用
private void button1_Click(object sender, EventArgs e)
{
// Image imgshow0 = Image.FromFile("src.jpg");
// pictureBox1.Image = imgshow0;
Thread threadA = new Thread(run_cap);
threadA.Start();
}
3,在form框架调用重绘函数将每一帧重绘到pictureBox1
this.pictureBox1.Paint += PictureBox1_Paint;
4,函数如下:
private void PictureBox1_Paint(object sender, PaintEventArgs e)
{
if (f)
{
Invalidate();pictureBox1.Invalidate();
e.Graphics.DrawImage(imgshow,0,0);
}
}
5,运行如下:
来源:https://blog.csdn.net/qq_34106574/article/details/83380732
标签:C#,OpenCvSharp,读取,摄像头
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java中的匿名对象定义与用法实例分析
2023-04-11 20:03:05
SpringBoot整合Druid数据源过程详解
2023-06-03 19:47:14
![](https://img.aspxhome.com/file/2023/3/103973_0s.png)
Spring项目中使用Junit单元测试并配置数据源的操作
2022-06-02 05:32:27
java导出Excel通用方法实例
2023-10-27 04:43:33
![](https://img.aspxhome.com/file/2023/0/62120_0s.png)
Go返回int64类型字段超出javascript Number范围的解决方法
2023-08-27 05:15:01
![](https://img.aspxhome.com/file/2023/6/107356_0s.png)
C#中的延时函数sleep
2022-08-05 13:16:49
SpringBoot ApplicationListener事件监听接口使用问题探究
2023-03-04 22:44:13
Java 判断数组是否相等的方法示例
2023-09-03 10:21:13
android播放gif格式图片示例
2023-08-01 18:41:36
JAVA 字符串加密、密码加密实现方法
2023-11-28 04:08:09
python只需30行代码就能记录键盘的一举一动
2023-06-27 18:22:12
![](https://img.aspxhome.com/file/2023/3/82403_0s.gif)
unity 如何使用LineRenderer 动态划线
2021-10-27 03:42:50
![](https://img.aspxhome.com/file/2023/9/102269_0s.jpg)
Spring JPA联表查询之OneToMany源码解析
2023-12-25 06:10:47
使用chatgpt实现微信聊天小程序的代码示例
2022-04-26 17:18:24
![](https://img.aspxhome.com/file/2023/0/67500_0s.jpg)
Java Filter 过滤器详细介绍及实例代码
2023-11-26 01:04:39
Java的优先队列PriorityQueue原理及实例分析
2023-03-14 08:11:00
Android RecyclerView 实现快速滚动的示例代码
2023-02-17 05:32:50
![](https://img.aspxhome.com/file/2023/2/138022_0s.gif)
Spring @Conditional注解原理解析
2022-10-04 16:09:51
Java 语言实现清除带 html 标签的内容方法
2021-07-29 23:47:43
浅析Java随机数与定时器
2022-06-04 16:21:10