[英]How can I get position of mouse click using opencvsharp?
我想在 IplImage 上獲得鼠標單擊的位置。 我搜索了它,但找不到任何東西。 沒有使用 openCVsharp 方法在 c# 中獲取鼠標位置的源代碼。 所以我嘗試了一些東西。 當代碼啟動時,它正在等待等待時間,當時我用鼠標單擊但沒有任何事情發生。 在等待鍵之后,代碼停止。 有沒有辦法在 IplImage 上獲得鼠標點擊的位置?
namespace mousedeneeme
{
class Program
{
static void Main(string[] args)
{
IplImage I_clean = Cv.LoadImage("Iclean.tiff", LoadMode.GrayScale);
String s = Cv.NamedWindow("I_clean image").ToString();
CvMouseCallback mo = new CvMouseCallback(on_mouse);
Cv.SetMouseCallback(s, on_mouse);
Cv.ShowImage("I_clean image", I_clean);
Cv.WaitKey(5000);
}
public static void on_mouse(MouseEvent me, int x, int y, MouseEvent me7) {
Console.WriteLine(x);
}
}
}
這是工作代碼
CvWindow w = new CvWindow("OpenCV Example")
w.OnMouseCallback+=new CvMouseCallback(on_mouse);
use += because you are binding event
試試這個
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
//callback function
void mouseEvent(int evt, int x, int y, int flags, void* param){
if(evt==CV_EVENT_LBUTTONDOWN){
printf("%d %d\n",x,y);
}
}
int main()
{
cvNamedWindow("MyWindow");
//assigning the callback function for mouse events
cvSetMouseCallback("MyWindow", mouseEvent, 0);
//load and display an image
IplImage* img = cvLoadImage("C:/Iclean.tiff");
cvShowImage("MyWindow", img);
//wait for key press
cvWaitKey(0);
//cleaning up
cvDestroyWindow("MyWindow");
cvReleaseImage(&img);
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.