상세 컨텐츠

본문 제목

#OpenCV 4로 배우는 컴퓨터 비전과 머신 러닝 - 4

Programing/OpenCV

by CouqueD'asse 2022. 5. 20. 15:40

본문

3.3 Vec과 Scalar 클래스

 

3.3.1 Vec 클래스

행 벡터 + 열 벡터 = 벡터 행렬

같은 자료형을 가진 원소 몇 개로 구성된 데이터 형식

 

3.3.2 Scalar 클래스

4채널 이하의 영상에서 픽셀 값을 표현하는 용도

void ScalarOp()
{
	Scalar gray = 128;
	cout << "gray : " << gray << endl;

	Scalar yellow(0, 255, 255);
	cout << "yellow : " << yellow << endl;

	Mat img1(256, 256, CV_8UC3, yellow);
	for (int i = 0; i < 4; i++)
	{
		cout << yellow[i] << endl;
	}
}

 

3.4 InputArray와 OutputArray 클래스

 

3.4.1 InputArray 클래스

Mat, vector<T>등 다양한 타입을 표현할 수 있는 인터페이스 클래스 (OpenCV 함수의 입력 인자 자료형으로 사용)

typedef const _InputArray& InputArray;
void InputArrayOp()
{
	uchar data1[] = { 1,2,3,4,5,6 };
	Mat mat1(2, 3, CV_8U, data1);
	printMat(mat1);

	vector<float> vec1 = { 1.2f, 3.4f, -2.1f };
	printMat(vec1);
}

void printMat(InputArray _mat)
{
	Mat mat = _mat.getMat();
	cout << mat << endl;
}

 

3.4.2 OutputArray 클래스

출력 영상을 함수의 return 구문으로 반환하지 않고 OutputArray 클래스의 참조를 함수 인자로 사용하여 결과 영상을 전달

typedef const _OutputArray& OutputArray;

관련글 더보기