728x90
300x250
[C#](OpenCVSharp 2.4.10) - 사진 출력

 

OpenCVSharp 2.4.10과 C#을 활용하여 사진을 출력하는 방법을 소개합니다.

(Introducing how to print photos using OpenCVSharp 2.4.10 and Visual C#.)

 

Nuget으로 "OpenCVSharp-AnyCPU 2.4.10"은 설치했다고 가정하고 진행합니다.

(Assume that you have installed "OpenCVSharp-AnyCPU 2.4.10" with Nuget.)

 


1. 로고 내려받기(Download the logo)

 

예제 그림으로 OpenCV 공식사이트에서 로고를 내려받습니다.

(Download the logo from the OpenCV official site as an example.)

 

https://opencv.org

 


2. 사용자 인터페이스 설계하기(Design the User Interface)

 

pictureBoxlpl1은 'SizeMode = StretchImage'로 해줍니다.

pictureBoxlpl1은 Size를 640 x 480으로 해줍니다.

(pictureBoxlpl1 is set to 'SizeMode = StretchImage'.)

(pictureBoxlpl1 sets the Size to 640 x 480.)

 

 

Form1은 Size를 800 x 600으로 해줍니다.

(Form1 sets the size to 800 x 600.)

 

 

아래 그림은 사용자 인터페이스를 임의로 그린 것입니다.

(The figure below is an arbitrary drawing of the user interface.)

 

 

Form1의 Load를 더블클릭해서 소스코드 작성할 수 있는 상태로 만들어줍니다.

 

 


3. 소스코드(Source Code)

 

소스코드입니다.(Source code.)

 

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 csharpImageLoad
{

    public partial class Form1 : Form
    {
        IplImage ipl;


        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            ipl = new IplImage("opencv-logo-1.png", LoadMode.AnyColor);
            pictureBoxIpl1.ImageIpl = ipl;
           
        }

    }

}

 

 


4. 시연(Demonstrate)

 

시연입니다.

그림의 원본은 훨씬 화려하다는 것을 알 수 있습니다.

(Demonstration.)

(Source of the picture can be seen that much glamor.)

 

 

 


5. 참고자료(Reference)

 

 

반응형
728x90
300x250
[C#](OpenCVSharp 2.4.10) - 카메라 인식

 

이번에 소개할 것은 Nuget 패키지의 "OpenCVSharp-AnyCPU"를 설치하여 카메라 인식을 소개할 것입니다.

레거시 상으로는 지원하지 않으나 현재 가장 안정화된 버전이라고 할 수 있습니다.

(This time, we will introduce camera recognition by installing "OpenCVSharp-AnyCPU" of Nuget package.)

(It's not supported legacy, but it's still the most stable version.)

 


1. 프로젝트에 라이브러리 설치하기(Install the library in your project)

 

프로젝트(P)->Nuget 패키지->"OpenCVSharp-Any"를 검색합니다.

OpenCVSharp 4 사용을 권유하는 문구가 있겠으나 무시하고 2.4를 설치하도록 합니다.

(Search for Project (P)-> Nuget Package-> "OpenCVSharp-Any".)

(Some suggest that you use OpenCVSharp 4, but ignore it and install 2.4.)

 

 

 


2. 사용자 인터페이스 설계(User Interface Design)

 

PictureBoxlpl, Timer1을 배치합니다.

(Place PictureBoxlpl, Timer1.)

 

 

pictureBoxlpl1의 Size는 640 x 480으로 해줍니다.

(The size of pictureBoxlpl1 is 640 x 480.)

 

 

timer1의 Interval은 33입니다.

timer1의 Enabled는 true입니다.

(timer1 has an Interval of 33.)

(Enabled for timer1 is true.)

 

 

 

 

 

폼 환경의 Load, FormClosing을 더블클릭해서 소스코드 작성이 가능한 상태로 해줍니다.

(Double-click Load, FormClosing in the form environment to make the source code available.)

 

 

 

 

 

다음은 Timer1에 관한 설정입니다.

Tick를 더블클릭하여 소스코드 작성이 가능한 상태가 되도록 해줍니다.

(The following are the settings for Timer1.)

(Double click Tick to make it possible to write source code.)

 

 


3. 소스코드 입력하기(Enter the source code)

 

소스코드를 타이핑 합니다.(Type the source code.)

 


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 OpenCVSharp_VideoCapture
{
    public partial class Form1 : Form
    {
        CvCapture capture;                        // OpenCVSharp 4부터 미지원
        IplImage src;                                 // OpenCVSharp 4부터 미지원

        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            src = capture.QueryFrame();
            pictureBoxIpl1.ImageIpl = src;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                capture = CvCapture.FromCamera(CaptureDevice.DShow, 0);

                /// Tip : 카메라를 2개 이상 이용한다면 0이 아닌 1로 입력하면 외부 카메라로 인식되어 출력됩니다.

                /// Tip : 동영상 파일 사용시 CvCapture.FromFile("경로")를 사용하여 동영상을 재생시킬 수 있습니다.
                capture.SetCaptureProperty(CaptureProperty.FrameWidth, 640);
                capture.SetCaptureProperty(CaptureProperty.FrameHeight, 480);
            }
            catch
            {
                timer1.Enabled = false;
            }

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Cv.ReleaseImage(src);
            if (src != null)
                src.Dispose();
        }

    }

}

 


4. 시연(Demonstrate)

 

아래의 그림은 동영상 재생을 시연한 것입니다. 모자이크 처리하였습니다.

 

 

반응형

+ Recent posts