নির্দিষ্ট পিক্সেলের মান পড়তে OpenCV-এ দুটি পদ্ধতি আছে: 'at' মেথড এবং 'ডাইরেক্ট অ্যাক্সেস' মেথড। এই আর্টিকেলে দুটি পদ্ধতিই ব্যাখ্যা করা হয়েছে।
'at' মেথড ব্যবহার করে পিক্সেল মান পড়া
নিচের প্রোগ্রামটি RGB ইমেজের (১০, ২৯) অবস্থানের পিক্সেল মান পড়ে।
উদাহরণ
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main() {
Mat image;
image = imread("sky.jpg");
// Vec3b ব্যবহার করে তিনটি চ্যানেলের মান পড়া
int x = image.at<Vec3b>(10, 29)[0]; // Blue channel
int y = image.at<Vec3b>(10, 29)[1]; // Green channel
int z = image.at<Vec3b>(10, 29)[2]; // Red channel
cout << "Value of blue channel:" << x << endl;
cout << "Value of green channel:" << y << endl; // এখানে মূল কোডে ভুল ছিল, ঠিক করা হয়েছে
cout << "Value of red channel:" << z << endl; // এখানেও ভুল ছিল, ঠিক করা হয়েছে
system("pause");
return 0;
}
কনসোল আউটপুট
Value of blue channel: [মান] Value of green channel: [মান] Value of red channel: [মান]
'Direct Access' মেথড ব্যবহার করে পিক্সেল মান পড়া
এই পদ্ধতিতে Mat_<Vec3b> টাইপ ডিক্লেয়ার করে সরাসরি অ্যাক্সেস করা যায়।
উদাহরণ
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main() {
Mat_<Vec3b> image;
image = imread("sky.jpg");
Vec3b pixel = image(10, 29); // সরাসরি পিক্সেল অ্যাক্সেস
cout << pixel << endl; // সব চ্যানেলের মান প্রিন্ট হবে
system("pause");
return 0;
}
আউটপুট
