OpenCV with C#
OpenCV 2021. 11. 20. 10:22 |반응형
C#으로 OpenCV를 사용해 보자.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenCvSharp;
namespace OpenCV
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
Mat mat = Cv2.ImRead(dlg.FileName);
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
}
// Mat to Bitmap 1
//Bitmap bitmap = new Bitmap(mat.ToMemoryStream());
//pictureBox1.Image = bitmap;
// Mat to Bitmap 2
//Bitmap bitmap = (Bitmap)Image.FromStream(mat.ToMemoryStream());
//pictureBox1.Image = bitmap;
// Mat to Bitmap 3
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(mat.ToBytes());
pictureBox1.Image = new Bitmap(memoryStream);
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
}
}
|
OpenCvSharp를 using 선언하고 버튼 클릭 이벤트 핸들러를 작성한다.
반응형
'OpenCV' 카테고리의 다른 글
OpenCV with C# and Camera (0) | 2021.12.29 |
---|---|
OpenCvSharp for Network (0) | 2021.12.28 |
OpenCV with Qt and MSVC in Windows (0) | 2021.09.26 |
OpenCV with Qt in Linux(Ubuntu) - 리눅스(우분투)에서 Qt로 OpenCV 이미지 디스플레이 (0) | 2021.02.13 |
Haar-cascade Detection 얼굴 검출 (10) | 2019.12.15 |