๐Ÿ“˜ Programming/OpenCV

[OpenCV] ๊ทธ๋ ˆ์ด ์Šค์ผ€์ผ(Gray Scale) ์˜์ƒ ๋งŒ๋“ค๊ธฐ

ํ•œ์ฝ”๋”ฉ 2020. 9. 20. 11:53
728x90
728x90
์†Œ์Šค์ฝ”๋“œ
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <Windows.h>
#include <string.h>
#include <iostream>

using namespace std;
using namespace cv;

void CreateGrayScaleImage() {
	// ๊ทธ๋ ˆ์ด ์Šค์ผ€์ผ ์˜์ƒ ๋งŒ๋“ค๊ธฐ
	Mat im1(32, 256, CV_8UC1, Scalar(0));

    // ๊ทธ๋ ˆ์ด ํ”ฝ์…€ ๋ ˆ๋ฒจ์„ ์ดˆ๊ธฐํ™”
	for (int i = 0; i < im1.rows; i++)
		for (int j = 0; j < im1.cols; j++)
			im1.at<uchar>(i, j) = j;
    
    // imshow()๋กœ ๋งŒ๋“  Mat ์˜์ƒ ์ถœ๋ ฅ
	imshow("im1", im1);
	waitKey();
}

int main() {
	CreateGrayScaleImage();
}

์˜์ƒ์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ• ์ค‘ ๊ทธ๋ ˆ์ด ๋ ˆ๋ฒจ๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ์˜์ƒ์„ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค.

 

๊ทธ๋ ˆ์ด ์Šค์ผ€์ผ ์˜์ƒ์€ Mat::at<T> (y,x)[์ฑ„๋„] ํ˜•ํƒœ๋กœ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

ํ–‰๋ ฌ์˜ ์ง€์ •๋œ ์›์†Œ์— ์ ‘๊ทผํ•˜๋Š” ํ…œํ”Œ๋ฆฟ ํ•จ์ˆ˜๋กœ, T ์ž๋ฃŒํ˜• ๋‹จ์œ„๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ ‘๊ทผํ•ฉ๋‹ˆ๋‹ค.

 

Mat::at<T> (const int *idx) : ์ •์ˆ˜ ๋ฐฐ์—ด๋กœ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅ

Mat::at<T> (Point pt) : ์ž…๋ ฅ ์‹œ, Point(x,y) ํ˜•ํƒœ๋กœ ์ž…๋ ฅ

 

์‹คํ–‰ ๊ฒฐ๊ณผ

 

 

728x90
๋ฐ˜์‘ํ˜•