๋ฐ˜์‘ํ˜•

OpenCVSharp์ด๋ž€?

OpenCvSharp ๋กœ๊ณ . ์ถœ์ฒ˜: GitHub
OpenCvSharp ๋กœ๊ณ . ์ถœ์ฒ˜: GitHub

OpenCV๋Š” Computer Vision ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋ฌด๋ฃŒ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ์ด OpenCV๋Š” C/C++ ์–ธ์–ด๋กœ ๊ฐœ๋ฐœ๋˜์–ด C++ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๊ธฐ๋ณธ์œผ๋กœ ์ œ๊ณตํ•˜์ง€๋งŒ, C#์€ ์ œ๊ณตํ•˜์ง€ ์•Š๋”๊ตฐ์š”. ๊ทธ๋ž˜์„œ ์ฐพ์•„๋ณด๋‹ˆ C#์—์„œ๋Š” OpenCV๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” C# Wrapping Library๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ์ค‘ ์ธ์ง€๋„๊ฐ€ ๋†’์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” Emgu CV์™€ OpenCVSharp์ด ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค.

Emgu CV์™€ OpenCVSharp์˜ ๊ฐ€์žฅ ํฐ ์ฐจ์ด์ ์œผ๋กœ, OpenCVSharp์˜ ๊ตฌ๋ฌธ์ด OpenCV C++ ํ•จ์ˆ˜ ๋ฐ ๋ฉ”์†Œ๋“œ์™€ ๋” ๊ฐ€๊น๋‹ค๋Š” ์ ์ด ์žˆ๋”๊ตฐ์š”. ์–ด๋–ค ๊ฒƒ์„ ์„ ํƒํ•˜๋“  ์ƒ๊ด€์€ ์—†์ง€๋งŒ, ๊ฐœ์ธ์ ์œผ๋ก  C++ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ๋น„์Šทํ•œ OpenCVSharp์ด ๋” ๋‚ซ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ  ๋งํฌ: https://stackoverflow.com/questions/37567494/what-is-the-difference-between-opencv-net-opencvsharp-and-emgucv

 

What is the difference between OpenCV.NET, OpenCVSharp and EmguCV?

What is the difference between OpenCV.NET, OpenCVSharp and EmguCV? They are derived from OpenCV. So, what is the difference in their design, implementation and application philosophies?

stackoverflow.com

๋ณธ๋ฌธ์˜ ์˜ˆ์ œ ์ฝ”๋“œ๋Š” ํ•˜๋‹จ์— ์ฒจ๋ถ€๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

OpenCVSharp ํ™˜๊ฒฝ ๊ตฌ์„ฑํ•˜๊ธฐ

๊ทธ๋Ÿผ ๋ณธ๊ฒฉ์ ์œผ๋กœ OpenCVSharp์„ C# ํ”„๋กœ์ ํŠธ์— ๊ตฌ์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. C# Windows Forms ์•ฑ์„ ์„ ํƒํ•˜๊ณ  ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์€ ExamOpenCVSharp์œผ๋กœ ์ƒ์„ฑํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

C# Windows Forms ์•ฑ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
C# Windows Forms ์•ฑ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

Visual Studio ์ƒ๋‹จ์˜ ๋„๊ตฌ ๋ฉ”๋‰ด์—์„œ NuGet ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž์˜ ์†”๋ฃจ์…˜์šฉ NuGet ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋ฉ”๋‰ด๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

์†”๋ฃจ์…˜์šฉ NuGet ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋ฉ”๋‰ด ํด๋ฆญ
์†”๋ฃจ์…˜์šฉ NuGet ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋ฉ”๋‰ด ํด๋ฆญ

์•„๋ž˜ ๊ทธ๋ฆผ์ฒ˜๋Ÿผ, NuGet-์†”๋ฃจ์…˜ ์ฐฝ์—์„œ ์ฐพ์•„๋ณด๊ธฐ ํƒญ์„ ํด๋ฆญํ•˜๊ณ  OpenCVSharp์„ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.

OpenCVSharp ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ
OpenCVSharp ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ

OpenCvSharp4 v4.5.2๋ฅผ ์„ ํƒํ•˜๊ณ , ์•„๋ž˜์™€ ๊ฐ™์ด ํ”„๋กœ์ ํŠธ๋ฅผ ์ฒดํฌํ•œ ํ›„ ์„ค์น˜ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ์— ์„ค์น˜ํ•˜๊ธฐ
ํ”„๋กœ์ ํŠธ์— ์„ค์น˜ํ•˜๊ธฐ

ํŠน๋ณ„ํ•œ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์™„๋ฃŒ ํ™”๋ฉด์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

NuGet ์„ค์น˜ ์™„๋ฃŒ ํ™”๋ฉด
NuGet ์„ค์น˜ ์™„๋ฃŒ ํ™”๋ฉด

๊ทธ๋ฆฌ๊ณ  ํ”„๋กœ์ ํŠธ์˜ ์ฐธ์กฐ ๋ถ€๋ถ„์— ์—ฌ๋Ÿฌ dll์ด ์ถ”๊ฐ€๋œ ๊ฒƒ๋„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€๋œ dll ๋ชฉ๋ก
ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€๋œ dll ๋ชฉ๋ก

์ฃผ์˜
 
 

์—ฌ๊ธฐ๊นŒ์ง€๋งŒ ์„ค์ •ํ•˜๊ณ  OpenCV ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์˜ˆ์™ธ์—์„œ "'OpenCvSharp.Internal.NativeMethods'์˜ ํ˜•์‹ ์ด๋‹ˆ์…œ๋ผ์ด์ €์—์„œ ์˜ˆ์™ธ๋ฅผ Throwํ–ˆ์Šต๋‹ˆ๋‹ค."๋ผ๋Š” ๋ฉ”์‹œ์ง€๊ฐ€ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์˜ ์ถ”๊ฐ€ ์ ˆ์ฐจ๋ฅผ ์ง„ํ–‰ํ•ด ์ฃผ์„ธ์š”.

์˜ˆ์™ธ ๋ฉ”์‹œ์ง€
์˜ˆ์™ธ ๋ฉ”์‹œ์ง€

์•„๋ž˜์˜ OpenCVSharp GitHub ํŽ˜์ด์ง€์— ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.

https://github.com/shimat/opencvsharp

 

shimat/opencvsharp

OpenCV wrapper for .NET. Contribute to shimat/opencvsharp development by creating an account on GitHub.

github.com

๊ทธ๋ฆฌ๊ณ  ์šฐ์ธก ์ค‘์•™์˜ Releases๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

OpenCVSharp ๋ฉ”์ธ ํ™”๋ฉด
OpenCVSharp ๋ฉ”์ธ ํ™”๋ฉด

NuGet์—์„œ ์„ค์น˜ํ•œ ๋ฒ„์ „๊ณผ ๋™์ผํ•œ ๋ฒ„์ „์ธ 4.5.2.20210404 ํƒœ๊ทธ์—์„œ OpenCvSharp-4.5.2-2021-0405.zip ํŒŒ์ผ์„ ํด๋ฆญํ•˜์—ฌ ๋‹ค์šด๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

OpenCvSharp ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ํ™”๋ฉด
OpenCvSharp ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ํ™”๋ฉด

๋‹ค์šด๋กœ๋“œํ•œ ํŒŒ์ผ์˜ ์••์ถ•์„ ํ•ด์ œํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ํŒŒ์ผ๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์••์ถ• ํ•ด์ œํ•œ ๋ชจ์Šต
์••์ถ• ํ•ด์ œํ•œ ๋ชจ์Šต

์—ฌ๊ธฐ์„œ NativeLib ํด๋” > win ํด๋” > x86 ๋˜๋Š” x64์˜ OpenCvSharpExtern.dll ํŒŒ์ผ์„ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

OpenCvSharpExtern.dll ํŒŒ์ผ ๋ณต์‚ฌํ•˜๊ธฐ
OpenCvSharpExtern.dll ํŒŒ์ผ ๋ณต์‚ฌํ•˜๊ธฐ

๊ทธ๋ฆฌ๊ณ  ExamOpenCVSharp ํ”„๋กœ์ ํŠธ ํด๋”์— ๋ถ™์—ฌ ๋„ฃ์Šต๋‹ˆ๋‹ค.

ExamOpenCVSharp ํ”„๋กœ์ ํŠธ์— ๋ถ™์—ฌ ๋„ฃ๊ธฐ
ExamOpenCVSharp ํ”„๋กœ์ ํŠธ์— ๋ถ™์—ฌ ๋„ฃ๊ธฐ

์ด์ œ ๋‹ค์‹œ Visual Studio๋กœ ๋Œ์•„์™€์„œ, ExamOpenCVSharp ํ”„๋กœ์ ํŠธ ์„ ํƒ ํ›„ ๊ธฐ์กด ํ•ญ๋ชฉ ์ถ”๊ฐ€ ๋ฉ”๋‰ด๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

ExamOpenCVSharp ํ”„๋กœ์ ํŠธ์—์„œ ํŒŒ์ผ ์ถ”๊ฐ€ ๋ฉ”๋‰ด ํด๋ฆญ
ExamOpenCVSharp ํ”„๋กœ์ ํŠธ์—์„œ ํŒŒ์ผ ์ถ”๊ฐ€ ๋ฉ”๋‰ด ํด๋ฆญ

ํŒŒ์ผ ์„ ํƒ ํ™”๋ฉด ์ฐฝ์ด ํ‘œ์‹œ๋˜๋ฉด ์šฐ์ธก ํ•˜๋‹จ์˜ ํ•„ํ„ฐ๋ฅผ ๋ชจ๋“  ํŒŒ์ผ๋กœ ์„ ํƒํ•˜๊ณ , OpenCvSharpExtern.dll ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

OpenCvSharpExtern.dll ํŒŒ์ผ ์ถ”๊ฐ€ ํ™”๋ฉด
OpenCvSharpExtern.dll ํŒŒ์ผ ์ถ”๊ฐ€ ํ™”๋ฉด

ํŒŒ์ผ ์ถ”๊ฐ€ ํ›„ dll์„ ์„ ํƒํ•˜๊ณ , ์ถœ๋ ฅ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ๋ณต์‚ฌ ์˜ต์…˜์„ ํ•ญ์ƒ ๋ณต์‚ฌ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

์ถœ๋ ฅ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ๋ณต์‚ฌ ์˜ต์…˜ ์„ ํƒ ํ™”๋ฉด
์ถœ๋ ฅ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ๋ณต์‚ฌ ์˜ต์…˜ ์„ ํƒ ํ™”๋ฉด

C# OpenCVSharp์œผ๋กœ Picture Box์— ์ด๋ฏธ์ง€ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

์ด์ œ ํ™˜๊ฒฝ ๊ตฌ์„ฑ์„ ๋ชจ๋‘ ๋งˆ์ณค์Šต๋‹ˆ๋‹ค. ๋ณธ๊ฒฉ์ ์œผ๋กœ ์ฝ”๋“œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ํผ์˜ UI๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฒ„ํŠผ๊ณผ PictureBox๋งŒ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

UI ๋ ˆ์ด์•„์›ƒ
UI ๋ ˆ์ด์•„์›ƒ

์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

using OpenCvSharp;

private void buttonLoad_Click(object sender, EventArgs e)
{
	try
	{
		OpenFileDialog dlg = new OpenFileDialog();
		if (dlg.ShowDialog() == DialogResult.OK)
		{
			Mat image = Cv2.ImRead(dlg.FileName);

			pictureBoxImage.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(image);
		}
	}
	catch(Exception exc)
	{
		MessageBox.Show(exc.Message);
	}
}

๋™์ž‘ ๊ฒฐ๊ณผ
๋™์ž‘ ๊ฒฐ๊ณผ

์•„์ฃผ ๊ฐ„๋‹จํ•˜์ฃ ? ์„ค๋ช…ํ•  ๋‚ด์šฉ๋„ ๋”ฑํžˆ ์—†์Šต๋‹ˆ๋‹ค. ๋ณธ๋ฌธ์—์„œ ์•„์ฃผ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์€ ํ”„๋กœ์ ํŠธ์— OpenCvSharpExtern.dll์„ ๋”ฐ๋กœ ์ถ”๊ฐ€ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด dll์ด ์—†์œผ๋ฉด ๊ณ„์†ํ•ด์„œ ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€๊ฐ€ ๋ฐœ์ƒํ•˜๋‹ˆ ๊ผญ ์•Œ๊ณ  ์‚ฌ์šฉํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

์•„๋ž˜ ์˜ˆ์ œ ์ฝ”๋“œ๋Š” ์šฉ๋Ÿ‰ ๋ฌธ์ œ๋กœ NuGet Package์™€ OpenCvSharpExtern.dll์€ ์ œ์™ธํ•˜๊ณ  ์ฒจ๋ถ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

ExamOpenCVSharp.zip
0.01MB

๋ฐ˜์‘ํ˜•