4
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <highgui.h>
using namespace cv;
using namespace std;
Mat image;
char window_name[20]="Get coordinates";
static void onMouse(int event, int x, int y, int f, void*){
cout << x << " " << y << endl;
//putText(image, "point", Point(x,y), CV_FONT_HERSHEY_PLAIN, 1.0, CV_RGB(255,0,0));
}
int main() {
namedWindow(window_name, CV_WINDOW_AUTOSIZE);
image = imread("image.png");
imshow(window_name, image);
setMouseCallback(window_name, onMouse, 0);
waitKey(0);
return 0;
}
這是在控制檯上打印鼠標指針的座標值並將鼠標指針懸停在圖像上的代碼。如果我希望在圖像上同樣打印座標,我該怎麼做?使用OpenCV在圖像上懸停時在圖像上打印鼠標指針的像素座標
太好了!拯救了我的一天! –