/// <summary> /// 指定されたウィンドウ内で発生するマウスイベントに対するコールバック関数を設定する /// </summary> /// <param name="windowName">ウィンドウの名前</param> /// <param name="onMouse">指定されたウィンドウ内でマウスイベントが発生するたびに呼ばれるデリゲート</param> /// <param name="userdata"></param> #else /// <summary> /// Sets the callback function for mouse events occuting within the specified window. /// </summary> /// <param name="windowName">Name of the window. </param> /// <param name="onMouse">Reference to the function to be called every time mouse event occurs in the specified window. </param> /// <param name="userdata"></param> #endif public static void SetMouseCallback(string windowName, CvMouseCallback onMouse, IntPtr userdata = default) { if (string.IsNullOrEmpty(windowName)) { throw new ArgumentNullException(nameof(windowName)); } if (onMouse == null) { throw new ArgumentNullException(nameof(onMouse)); } NativeMethods.highgui_setMouseCallback(windowName, onMouse, userdata); }
/// <summary> /// 指定されたウィンドウ内で発生するマウスイベントに対するコールバック関数を設定する /// </summary> /// <param name="windowName">ウィンドウの名前</param> /// <param name="onMouse">指定されたウィンドウ内でマウスイベントが発生するたびに呼ばれるデリゲート</param> #else /// <summary> /// Sets the callback function for mouse events occuting within the specified window. /// </summary> /// <param name="windowName">Name of the window. </param> /// <param name="onMouse">Reference to the function to be called every time mouse event occurs in the specified window. </param> #endif public static void SetMouseCallback(string windowName, CvMouseCallback onMouse) { if (string.IsNullOrEmpty(windowName)) throw new ArgumentNullException("windowName"); if (onMouse == null) throw new ArgumentNullException("onMouse"); Window window = Window.GetWindowByName(windowName); if (window != null) { window.OnMouseCallback += onMouse; } }
public MainWindowViewModel() { mWin = new OpenCvSharp.Window("Source Window"); CvMouseCallback callback = new CvMouseCallback(CvMouseMove); Cv2.SetMouseCallback("Source Window", callback); mImagePoints = new List <Point2f>(); //Initialize source points. //Top left corner of paper list taken as the origin of the coordinate system. //Bypassing the points is clockwise. mWorldPoints = new List <Point3f>() { new Point3f(0, 0, 0), new Point3f(210, 0, 0), new Point3f(210, 297, 0), new Point3f(0, 297, 0) }; ResultIsUnknown(); }
public Mat Crop() { using (CroppingWindow = new OpenCvSharp.Window("Cropper", WindowMode.FullScreen, srcImage)) { CvMouseCallback onMouse = new CvMouseCallback(mouseCallback); CroppingWindow.SetMouseCallback(onMouse); CvTrackbarCallback2 onZoom = new CvTrackbarCallback2(trackbarCallback); CvTrackbar zoom = CroppingWindow.CreateTrackbar2("Zoom", 100, 200, onZoom, null); Cv2.WaitKey(); // This line is very important // OpenCV is written in C++, which means it's unmanaged. // So when a delegate callback variable is passed to it as a function point, // GC in C# can no longer identify the life cycle of this delegate variable // It's our reponsebility to make sure GC in C# will not collect it when it's still in use. // Otherwise an exception will be thrown. GC.KeepAlive(onMouse); } // seems that srcImage will be released by GC, so I must return a copy of it return(srcImage.Clone()); }
/// <summary> /// 指定されたウィンドウ内で発生するマウスイベントに対するコールバック関数を設定する /// </summary> /// <param name="onMouse">指定されたウィンドウ内でマウスイベントが発生するたびに呼ばれるデリゲート</param> /// <param name="userdata"></param> #else /// <summary> /// Sets the callback function for mouse events occuting within the specified window. /// </summary> /// <param name="onMouse">Reference to the function to be called every time mouse event occurs in the specified window. </param> /// <param name="userdata"></param> #endif public void SetMouseCallback(CvMouseCallback onMouse, IntPtr userdata = default) { Cv2.SetMouseCallback(name, onMouse, userdata); }
public static extern void highgui_setMouseCallback(string winName, [MarshalAs(UnmanagedType.FunctionPtr)] CvMouseCallback onMouse, IntPtr userData);
public static void cvSetMouseCallback(String window_name, CvMouseCallback on_mouse) { cvSetMouseCallback(window_name, on_mouse, (IntPtr)0); }
public extern static void cvSetMouseCallback(/* const char* */ String window_name, CvMouseCallback on_mouse, IntPtr param /*CV_DEFAULT(NULL)*/);
/// <summary> /// 指定されたウィンドウ内で発生するマウスイベントに対するコールバック関数を設定する /// </summary> /// <param name="windowName">ウィンドウの名前</param> /// <param name="onMouse">指定されたウィンドウ内でマウスイベントが発生するたびに呼ばれるデリゲート</param> #else /// <summary> /// Sets the callback function for mouse events occuting within the specified window. /// </summary> /// <param name="windowName">Name of the window. </param> /// <param name="onMouse">Reference to the function to be called every time mouse event occurs in the specified window. </param> #endif public static void SetMouseCallback(string windowName, CvMouseCallback onMouse) { if (string.IsNullOrEmpty(windowName)) throw new ArgumentNullException("windowName"); if (onMouse == null) throw new ArgumentNullException("onMouse"); Window window = Window.GetWindowByName(windowName); if (window != null) { window.OnMouseCallback += onMouse; } }