728x90
300x250

[프로그래밍 퀴즈(Quiz)] 범용적인 문제 - 재귀 호출(General Problem-Recursive Calls)


1부터 n까지의 합을 구하는 프로그램을 작성한다.

과 같이 표현되는 것은 순차적인 방법으로 표현되어서 for, while과 같은 반복문을 사용해서 구현할 수 있을 것이다.

두 번째, sum(n)을 다른 방법으로 즉, 재귀적인 방법으로 표현하면 다음과 같다.


            

            


컴퓨터 프로그래밍 코드를 통해서 알아보도록 하자.


#include <iostream>

using namespace std;

int sum(int n);
int main(){

    cout << sum(10) << endl;
}

int sum(int n){

    if ( n == 1 ){
        return 1;
    }
    else{
        return sum(n-1) + n;
    }
}



반응형
728x90
300x250
[MS Visual C++] Visual Studio 2019(C++ MFC) 사용하기 및 OpenCV 4.1 환경설정


Microsoft Windows 10, Visual Studio 2019으로 진행하였습니다.

C++ MFC를 사용하면, 종종 프로그램이 강제로 튕기는 것을 경험할 수 있습니다.

C#으로 가는 것이 좋을 거 같다는 의견입니다.


(I went to Microsoft Windows 10, Visual Studio 2019.)
(With C ++ MFC, you can often experience program bounces.)
(I think it would be nice to go to C#.)



1. MFC 설치하기


Visual Studio 2017, Visual Studio 2019부터는 MFC를 자동으로 지원하지 않습니다. 개별적으로 설치해야 합니다.

(Starting with Visual Studio 2017, Visual Studio 2019, MFC is not automatically supported.)



2. OpenCV 시작하기(Getting started with OpenCV)

OpenCV는 아래의 사이트에서 내려받을 수 있습니다. (OpenCV can be downloaded from the following site.)

https://www.opencv.org




Learn More를 클릭합니다.



OpenCV - 4.1.2에서 Windows를 클릭합니다.

(In OpenCV-4.1.2, click Windows.)






다운받은 파일을 Extract로 풀어줍니다.(Extract the downloaded file with Extract.)





2-1. 압축 풀었던 OpenCV 폴더 C:\로 이동하기(2-1. Navigate to the Unzipped OpenCV folder C:\)


압축 풀었던 Opencv 폴더를 C:\로 이동합니다.(Move the extracted Opencv folder to C:\.)







3. 프로젝트 구성하기(Organize your project)


프로젝트 구성입니다. MFC 앱을 검색하여 더블클릭하면, 아래의 그림을 볼 수 있습니다.

(Project configuration. Search for the MFC app and double-click it to see the picture below.)


단일 문서, 대화 상자, 다중 문서에 대해서 전부 소개하지 않았기 때문에 깊이 생각하지 않으셨으면 합니다.

(I didn't introduce a single document, a dialog box, or multiple documents, so I don't want to think deeply about it.)



4. 프로젝트 속성 변경하기(Changing project properties)


제일 중요한 부분이 아니겠느냐 싶습니다.

이 부분 설정을 해놓으면 코딩은 구역에 프로그램 코드를 작성해서 잘 동작하도록 만들어주면 되겠습니다.

(I think it's the most important part.)
(With this part set up, the coding can be done by writing program code in the section.)












참고하면 흥미로운 정보(Interesting information for your reference)


-> 카테고리에 opencvCsharp 이라는 코너를 운영하고 있습니다. 같이 병행해서 보면 도움이 될 것입니다.

(Categories are operating in the corner of opencvCsharp. It will be helpful to see them in parallel.)

반응형
728x90
300x250

[이야기(Story)] 티맥스 OS 사용후기 - 이클립스(Eclipse), APT, 인터넷 뱅킹


티맥스 OS(Tmax OS)를 직접 사용해보았습니다.

개발자 관점으로 자주 사용할 수 있는 프로그램을 대상으로 시연하였습니다.



1. Eclipse(2019-11-12)


이클립스 사용에 관한 것입니다.







Java가 설치되지 않았다고 알리는 메시지입니다.

처음 순수한 설치를 하면 자바 자체가 깔려있지 않습니다.



데비안, 우분투 리눅스에서 자주 사용했던 apt-get install 명령어는 지원은 합니다.

소스 주소 등을 알아내고 배포판 계열을 맞춰내면 가능할지는 모르겠습니다.(태스트 해보진 않았음.)




2. OpenJDK 설치하기


https://openjdk.java.net 에서 수동으로 설치할 수 있는 파일을 내려받을 수 있습니다.

설치 방법은 시중에 돌아다니는 "우분투 18.04, 데비안 10"과 동일하게 진행할 수 있습니다.



tar xvfz openjdk.tar.gz

.......

sudo mkdir /usr/local/java

sudo mv /jdk13 /usr/local/java


vim /etc/profile.d/jdk13


export JAVA_HOME ...........

export PATH=............


:wq


source /etc/profile


java -version


이런 형태로 진행하여 설치할 수 있습니다.














3. Eclipse 설치 창 동작 시켜보기(2019-11-12)


동작한다고 보면 됩니다.

다만, 최근 출시된 eclipse 버전이 오류가 많아서 튕길 수 있습니다.



















4. APT 업데이트


debian.org 소스와, tmaxos.com 소스 경로가 나옵니다.





반응형
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)

 

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

 

 

반응형
728x90
300x250

[수학(Math)] 14. 역행렬(Inverse)

 

이 절에서는 정사각행렬 에 어떤 행렬을 곱하여 항등행렬이 되는 행렬에 대한 기본적인 성질에 대하여 살펴보기로 한다.

 

(정의)

정사각행렬 에 대하여 다음 조건을 만족하는 행렬 가 존재하면 행렬 를 정칙행렬(가역행렬, invertible matrix)이라고 한다.

 

이 때 행렬 를 행렬 의 역행렬(inverse)이라고 하고 로 나타낸다.

 

(예제) 행렬 에 대하여

이므로 이다.

 

정칙행렬의 역행렬은 유일하게 존재한다는 사실을 다음 정리에서 보일 수 있다.

 

정리:

= 유일하다.

의 역행렬이라 하자.

 

정사각행렬 가 정칙행렬이면 의 역행렬은 유일하게 존재한다.

 

(증명) 만일 의 역행렬이라고 가정하면

이다.

따라서 가 되어 의 역행렬은 유일하게 존재한다.

 

임의의 정사각행렬 에 대하여 역행렬이 반드시 존재하는 것은 아니다. 다음의 예제를 살펴보자.

 

(예제) 행렬 의 역행렬이 존재한다고 가정하고 그 역행렬을 라고 하면 다음이 성립한다.

 

 

따라서

 

이다. 그런데 이 식을 만족시키는 실수 는 존재하지 않는다. 따라서 행렬 가 행렬 의 역행렬이 된다는 사실에 모순이 된다.

즉, 행렬 는 정칙행렬이 아니다.

 

행렬 가 정칙행렬일 때 가 정칙행렬이라고 할 수 없다는 사실을 다음 예를 통하여 알 수 있다.

 

(예제) 두 행렬 는 정칙행렬이지만 이므로 는 정칙행렬이 아니다. 따라서 임의의 두 정칙행렬의 합은 정칙행렬이라고 할 수 없다.

 

(정리)

정사각행렬 와 실수 에 대하여 다음이 성립한다.

(1)

(2)

(3)

 

 

(증명)

 

(1) 이므로 의 역행렬이다. 즉, 이다.

 

(2)

    

   

     

  

    이므로

   이다.

 

(3) 이므로 등식이 성립한다.

 

(예제) 두 행렬 는 정칙행렬이다. 또한

이므로

 

이다. 따라서 이고 이 성립한다.

 

(정리)

정사각행렬 가 정칙행렬이면 는 정칙행렬이다. 또한 다음이 성립한다.

 

 

(증명)

가 정칙행렬이므로 이다. 따라서,

이 되어 는 정칙행렬이고 이다.

 

(예제) 행렬 는 정칙행렬이고 역행렬은 이다. 또한

는 정칙행렬이고 역행렬은 이다. 따라서

 

 

(정리)

대칭행렬 가 정칙행렬이면 역행렬 도 대칭행렬이다.

 

(증명)

가 대칭행렬이므로 다음 관계가 성립한다.

 

 

따라서, 는 대칭행렬이 된다.

 

(예제)

 

행렬 에 대하여

 

 

이므로 는 대칭행렬이고 정칙행렬이다. 또한

 

이므로 의 역행렬 도 대칭행렬이다.

 

(정리)

교대행렬 가 정칙행렬이면 역행렬 도 교대행렬이다.

 

(증명) 가 교대행렬이므로 다음 관계가 성립한다.

 

따라서, 는 교대행렬이 된다.

 

(예제) 행렬 에 대하여

                

이므로 는 교대행렬이고 정칙행렬이다. 또한

 

이므로 의 역행렬 도 교대행렬이다.

 

 

반응형
728x90
300x250
[C#](OpenCVSharp 4) - Face Detection(얼굴 인식)

 

Face Detection(얼굴 인식)을 C# GUI환경에서 구현하는 방법에 대해 소개하려고 합니다.

OpenCV 공식 github사이트에서 라이브러리를 내려받은 후 진행할 것입니다.

(Let me introduce how to implement Face Detection in C# GUI environment.We will proceed after downloading the library from the official OpenCV github site.)

 

 


1. OpenCV 프로젝트 내려받기

 

http://github.com/opencv/opencv

http://github.com/opencv/opencv/data

 

 

 

 

이 파일이 얼굴 인식에 사용되는 중요한 라이브러리입니다.

(This file is an important library for face recognition.)

얼굴 인식 기능을 사용하려면, 프로젝트에 포함시켜야 합니다.
(To use face detection, you must include it in your project.)

 

[첨부(Attachment)]

haarcascade_frontalface_alt.7z

 

 


2. Nuget으로 OpenCVSharp 4 설치하기(Installing OpenCVSharp 4 with Nuget)

 

프로젝트->Nuget 패키지 관리를 클릭합니다.

"OpenCvSharp4"를 검색하여 설치하도록 합니다.
(Click Project-> Nuget Package Management.Search for "OpenCvSharp4" and install it.)

 

 

 


3. 사용자 인터페이스 구성(Configure the User Interface)


OpenCvSharp.UserInterface 내에 있는 PictureBoxlpl 하나, Timer 하나를 배치합니다.

 

Form1은 Load 코드를 활성화합니다.

Timer1은 Enabled = true로 해주고, Interval은 33으로 해줍니다.

Timer1의 Tick를 활성화해줍니다.

(Form1 activates the Load code.)

(Timer1 sets Enabled = true and Interval sets 33.)

(Activate Tick of Timer1.)

 


4. 프로젝트 내에 중요한 설정하기(Make important settings within your project)

 

세 가지 사항을 별표로 하였습니다.(Three points are starred.)

 

 

 

 

 

 

 

haarcascade_frontalface_alt.xml, opencvSharpExtern.dll은 출력 디렉터리에 복사 항목을 "새 버전이면 복사"에 체크해줍니다.

OpenCVSharpExtern.dll은 아래의 사이트에서 내려받을 수 있습니다.
(haarcascade_frontalface_alt.xml, opencvSharpExtern.dll checks "Copy if newer version" to the output directory.

OpenCVSharpExtern.dll can be downloaded from the site below.)

 

https://github.com/shimat/opencvsharp/releases

 

 

 


5. 코드 작성

 

코드를 작성해봅니다.

 

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 CsharpFaceDetection
{
    public partial class Form1 : Form
    {

        VideoCapture video;
        Mat frame = new Mat();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            try
            {
                video = new VideoCapture(0);
                video.FrameWidth = 640;
                video.FrameHeight = 480;
            }
            catch
            {
                timer1.Enabled = false;
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            int sleepTime = (int)Math.Round(1000 / video.Fps);

            String filenameFaceCascade = "haarcascade_frontalface_alt.xml";
            CascadeClassifier faceCascade = new CascadeClassifier();

            if (!faceCascade.Load(filenameFaceCascade))
            {
                Console.WriteLine("error");
                return;
            }

            video.Read(frame);

            // detect
            Rect[] faces = faceCascade.DetectMultiScale(frame);
            Console.WriteLine(faces.Length);

            foreach (var item in faces)
            {
                Cv2.Rectangle(frame, item, Scalar.Red); // add rectangle to the image
                Console.WriteLine("faces : " + item);
            }

            // display
            pictureBoxIpl1.ImageIpl = frame;

            Cv2.WaitKey(sleepTime);
        }
    }
}

 

[첨부(Attachment)]

Form1.7z

 


6. 시연하기(Demonstrate)

 

 


7. 참고자료(Reference)

 

1. [C#](OpenCVSharp 4) - c#에서 OpenCV 카메라 열기와 처음 시작하기, Last Modified 2019-11-10, Accessed by 2019-11-11, https://yyman.tistory.com/1350?category=809859

2. opencv/haarcascade_frontalface_alt.xml at master · opencv/opencv , Last Modified , Accessed by 2019-11-11,

https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_frontalface_alt.xml

3. opencv/opencv: Open Source Computer Vision Library, Last Modified, Accessed by 2019-11-11,

https://github.com/opencv/opencv

4. Releases · shimat/opencvsharp, Last Modified 2019-11-10, Accessed by 2019-11-11, https://github.com/shimat/opencvsharp/releases

반응형
728x90
300x250
[C#](OpenCVSharp 4) - Image 출력하기
 

Microsoft C# OpenCVSharp 4로 그림을 출력하는 방법에 대해서 간단하게 소개하겠습니다.
(Here's a quick introduction to how to print a picture with Microsoft C # OpenCVSharp 4.)

 


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

 

아래의 그림은 사용자 인터페이스를 설계한 것입니다. 콘솔환경이 아니라 윈도우 환경에서 시연하였습니다.
(The figure below shows the design of the user interface. It was demonstrated in the Windows environment, not the console environment.)

 

 


2. 폼 Load 기능 설계(Form Load Function Design)

 

폼 기능 설계입니다. 솔루션 탐색기 아래에 Form1로 선택하시고 번개표시를 클릭하면 아래의 그림을 볼 수 있습니다.

Load의 빈 칸을 더블클릭하면 코드를 생성할 수 있습니다.
(Form feature design.
Select Form1 under Solution Explorer and click the lightning bolt to see the figure below.You can generate code by double clicking on the blank of Load.)

 

 


3. 코드 작성(Write the code)

 

코드를 입력하면 됩니다.(Just enter the 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 OpenCVSharpImage
{
    public partial class Form1 : Form
    {

        Mat image;


        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {

            image = Cv2.ImRead("cat.jpg", ImreadModes.Grayscale);
            // Cv2.ImShow("image", image);
            // Cv2.WaitKey(0);
            // Cv2.DestroyAllWindows();

            pictureBoxIpl1.ImageIpl = image;


        }

    }

}

 

첨부(Attachment)

191110 - cat.7z // 사진 파일


4. 완성(complete)

 

그레이 형태로 완성이 되었습니다.

 

완성된 모습입니다.(It's finished.)

 


5. 영상으로 시연된 모습 구경하기(Watch the video demonstration)

 

OpenCVSharp 4 그림 출력에 대해서 시연하였습니다.
(Demonstration of OpenCVSharp 4 figure output.)

 

 

 

반응형

+ Recent posts