我想获得鼠标点击pplimage的位置。我把它弄干了但我找不到任何东西。使用openCVsharp方法在c#中获取鼠标位置没有任何来源。所以我尝试了一些东西。当代码启动时,它正在等待那个时候我用鼠标点击但没有什么是幸福的等待时间。在waitkey之后代码停止了。你可以帮帮我吗?有没有办法通过鼠标点击获得plimage的位置?
命名空间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);
}
}
}
答案 0 :(得分:1)
这是工作代码
CvWindow w = new CvWindow("OpenCV Example")
w.OnMouseCallback+=new CvMouseCallback(on_mouse);
use += because you are binding event
答案 1 :(得分:0)
试试这个
#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;
}