C# OpenCV4
Webcam 사용하기
OpenCv4를 사용하기에, 기본적으로 OpenCV4 Nuget 추가를 해주셔야합니다.
Code
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Point = OpenCvSharp.Point;
namespace WebCam
{
public partial class Form1 : Form
{
Task refresh;
VideoCapture _capture;
public Form1()
{
InitializeComponent();
_capture = new VideoCapture();
}
private void Form1_Load(object sender, EventArgs e)
{
_capture.Open(0, VideoCaptureAPIs.ANY);
if (!_capture.IsOpened())
{
Close();
return;
}
ClientSize = new System.Drawing.Size(_capture.FrameWidth, _capture.FrameHeight);
refresh = Task.Run(() => RefreshFuc());
}
private void RefreshFuc()
{
try
{
while (true)
{
using (var VideoMat = _capture.RetrieveMat())
{
using (var OldImg = pictureBox1.Image)
{
pictureBox1.Image = VideoMat.ToBitmap();
}
}
Thread.Sleep(10);
}
}
catch(Exception ex)
{
}
}
}
}
Result
'🔥 Programming > OpenCV' 카테고리의 다른 글
[OpenCV4] C# OpenCV4 배경색 변경 (0) | 2022.11.10 |
---|---|
[OpenCV4] C# OpenCV4 Template Matching (0) | 2022.10.19 |
[OpenCV4] C# OpenCV4 Gamma (0) | 2022.09.23 |
[OpenCV4] C# OpenCV4 Houghline (직선검출) (0) | 2022.08.18 |
[OpenCV4] C# OpenCV4 두 이미지 합치기 (0) | 2022.08.17 |