5
का उपयोग करके निर्देशांक और पिक्सेल मान प्रिंट करें यह कोड है जिसे मैंने कोशिश की, केवल समन्वय मान मुद्रित हैं लेकिन पिक्सेल मान नहीं।माउस कॉलबैक
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
void onMouse(int event, int x, int y, int, void*);
using namespace cv;
Mat img = cv::imread("b.jpg", 0); // force grayscale
Mat thresh=Mat::zeros(img.size(),CV_8UC1);
int main(int argc, char **argv)
{
if(!img.data) {
std::cout << "File not found" << std::endl;
return -1;
}
threshold(img,binary,50,255,THRESH_TOZERO);
namedWindow("thresh");
setMouseCallback("thresh", onMouse, 0);
imshow("thresh",thresh);
}
void onMouse(int event, int x, int y, int, void*)
{
if(event != CV_EVENT_LBUTTONDOWN)
return;
Point pt = Point(x,y);
std::cout<<"x="<<pt.x<<"\t y="<<pt.y<<"\t value="<<thresh.at<uchar>(x,y)<<"\n";
}
मैं के रूप में उत्पादन मिला: -
समन्वय मूल्यों मुद्रित कर रहे हैं लेकिन पिक्सेल मान ठीक से मुद्रित नहीं कर रहे हैं। मैंने क्या गलती की है ??
आप @berak धन्यवाद। एक और qn: .at (वाई, एक्स) में, कौन सा पंक्ति संख्या और स्तंभ संख्या का प्रतिनिधित्व करता है ?? –
पर (row_no, column_no) 'मूल रूप से: y = row_no, x = column_no' – berak