如何使用 C++ 在 OpenCV 中計算影像通道數?
在本主題中,我們將瞭解如何找出影像的通道數。在執行程式後,通道數將顯示在控制檯視窗中。
為了獲得通道數,我們使用了 OpenCV 的一個名為'channels()'的類。當我們將影像矩陣作為 '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;
}輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP