ইমেজের চ্যানেল সংখ্যা জানতে OpenCV-র channels() মেথড ব্যবহার করা হয়। এটি ইন্টিজার ভ্যালু রিটার্ন করে (গ্রে স্কেলের জন্য ১, RGB-এর জন্য ৩, RGBA-এর জন্য ৪)।
উদাহরণ কোড
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main() {
Mat img = imread("colors.jpg");
int num_channels = img.channels();
cout << "The number of channel(s) = " << num_channels << endl;
system("pause");
waitKey(0);
return 0;
}
আউটপুট

কনসোলে চ্যানেলের সংখ্যা প্রিন্ট হবে (রঙিন ছবির জন্য সাধারণত ৩)।