ในหัวข้อนี้ เราจะเข้าใจวิธีค้นหาจำนวนช่องของรูปภาพ หลังจากรันโปรแกรม หมายเลขช่องจะแสดงในหน้าต่างคอนโซล
เพื่อให้ได้จำนวนช่อง เราได้ใช้คลาสของ 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;
} ผลลัพธ์
