Computer >> 컴퓨터 >  >> 프로그램 작성 >> C++

C++를 사용하여 OpenCV에서 이미지의 채널 수를 계산하는 방법은 무엇입니까?

<시간/>

이 주제에서는 이미지의 채널 수를 찾는 방법을 이해합니다. 프로그램을 실행하면 콘솔 창에 채널 번호가 표시됩니다.

채널 번호를 얻기 위해 'channels()'라는 OpenCV 클래스를 사용했습니다. 이미지 행렬을 'channels()' 클래스의 객체로 전달하면 채널에 정수 값을 제공합니다.

다음 프로그램은 채널 수를 계산하여 콘솔 창에 표시합니다.

예시

#include<iostream>
#include<opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
   Mat image_load;//Declaring a matrix to load the image//
   image_load = imread("colors.jpg");//Loading image in the matrix//
   int number_of_channel = image_load.channels();//Storing the number of channels in the variable//
   cout << "The number of channel(s)=" << number_of_channel << endl;//Showing the number of channels//
   system("pause");//Pausing the system to check the number of channel//
   waitKey(0);
   return 0;
}

출력

C++를 사용하여 OpenCV에서 이미지의 채널 수를 계산하는 방법은 무엇입니까?