๐Ÿ“˜ Programming/OpenCV

[OpenCV] OpenCV ์‹œ์ž‘ํ•˜๊ธฐ(์„ค์น˜, ํ™˜๊ฒฝ ์„ค์ •, ํŒŒ์ผ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ)

ํ•œ์ฝ”๋”ฉ 2020. 9. 8. 12:34
728x90
728x90
OpenCV(Open source Computer Vision) LibraryOpenCV ๋Š” ์˜คํ”ˆ ์†Œ์Šค ์ปดํ“จํ„ฐ ๋น„์ „ ๋ฐ ๊ธฐ๊ณ„ ํ•™์Šต ์†Œํ”„ํŠธ์›จ์–ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค.

์ปดํ“จํ„ฐ ํ•™์Šต, ์ปดํ“จํ„ฐ ๋น„์ „, ์•Œ๊ณ ๋ฆฌ์ฆ˜, ์ˆ˜ํ•™ ์—ฐ์‚ฐ, ๋น„๋””์˜ค ์บก์ฒ˜, ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ๋“ฑ๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๋ชฉ์ ์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

https://sourceforge.net/projects/opencvlibrary/files/4.1.1/opencv-4.1.1-vc14_vc15.exe/download

์œ„ url ์ ‘์† ํ›„ 5์ดˆ๊ฐ€ ์ง€๋‚˜๋ฉด ์ž๋™ ๋‹ค์šด๋กœ๋“œ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์••์ถ•์„ ํ’€๊ณ  ์„ค์น˜๋ฅผ ํ•˜์‹ค ๋•Œ, C๋“œ๋ผ์ด๋ธŒ์— ์„ค์น˜ํ•˜๋ฉด ํŽธํ•ฉ๋‹ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

OpenCV ํ™˜๊ฒฝ ์„ค์ •

๋ฉ”๋‰ด ๋ฐ”์—์„œ [ํ”„๋กœ์ ํŠธ(P)] [์†์„ฑ(P)]๋กœ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค.

์•„๋ž˜ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด ์„ค์ •ํ•ด์ฃผ์„ธ์š”.

์‹ค์Šต - ์ด๋ฏธ์ง€ ํŒŒ์ผ ์ฝ์–ด์˜ค๊ธฐ

OpenCV๋ฅผ ํ™œ์šฉํ•˜๋ ค๋ฉด ๋จผ์ € ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์™€์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ์†Œ์Šค์ฝ”๋“œ๋Š” ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์‹ค์Šต์ž…๋‹ˆ๋‹ค. ์šฐ์„ , ์•„๋ž˜ ์‹ค์Šต์— ์‚ฌ์šฉ๋  ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œ ํ•ด์ค์‹œ๋‹ค.

Lenna512.png
0.45MB

์•„๋ž˜๋Š” ์†Œ์Šค์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <Windows.h>
#include <string.h>
#include <iostream>

using namespace std;
using namespace cv;

string OpenFileDialog() {
	char name[MAX_PATH] = { 0, };
	OPENFILENAMEA ofn;
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(OPENFILENAMEA);
	ofn.hwndOwner = NULL;
	ofn.lpstrFilter = "๋ชจ๋“ ํŒŒ์ผ(*.*)\0*.*\0";
	ofn.lpstrFile = name;
	ofn.nMaxFile = MAX_PATH;
	ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
	ofn.lpstrDefExt = "";

	string strName;
	if (GetOpenFileNameA(&ofn)) 
		strName = name;

	return strName;
}

int main() {
	auto name = OpenFileDialog();
	if (name != "") {
		ImreadModes type[] = { IMREAD_GRAYSCALE,IMREAD_COLOR };
		for (int i = 0; i < 2; i++) {
			auto image = imread(name, type[i]);

			cout << "Depth = " << image.depth() << "\n";
			cout << "Channels Num = " << image.channels() << "\n";
			cout << "Width = " << image.cols << "\n";
			cout << "Height = " << image.rows << "\n";

			imshow("์˜์ƒ๋ณด๊ธฐ", image);
			waitKey(0);
		}
	}
}

 

์†Œ์Šค์ฝ”๋“œ์— ์ž‘์„ฑ๋œ OpenFileDialog()ํ•จ์ˆ˜๋Š” ํŒŒ์ผ ์„ ํƒ ๋‹ค์ด์–ผ๋กœ๊ทธ๋ฅผ ๋„์šฐ๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.

์†Œ์Šค์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผํ•˜๋ฉด ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.

์œ„์— ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์™€์„œ ์‹คํ–‰ํ•˜๋ฉด ์ด๋ฏธ์ง€์™€ ํ•จ๊ป˜ ์ฝ˜์†” ์ฐฝ์— ์ด๋ฏธ์ง€ ๋„“์ด, ๋†’์ด ๋“ฑ ์ •๋ณด๊ฐ€ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.

 

 

 

728x90
๋ฐ˜์‘ํ˜•