0

我想获得鼠标点击 IplImage 的位置。我搜索了它,但我找不到任何东西。在 c# 中没有使用 openCVsharp 方法获取鼠标位置的来源。所以我尝试了一些东西。当代码启动时,它正在等待等待时间,当时我用鼠标单击,但没有任何事情发生。在等待键之后,代码停止。有没有办法获得鼠标点击 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);
        }


    }
}
4

2 回答 2

1

这是工作代码

CvWindow w = new CvWindow("OpenCV Example") 

w.OnMouseCallback+=new CvMouseCallback(on_mouse);

use += because you are binding event
于 2014-04-30T12:13:53.343 回答
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;
   } 
于 2013-01-22T14:17:30.590 回答