private void CallbackOpenCVAnnotate(MouseEventTypes e, int x, int y, MouseEventFlags flags, IntPtr userdata) { if (e == MouseEventTypes.LButtonDown) { point2Fs.Add(new Point2f(x, y)); if (point2Fs.Count == 4) { srcPoints = point2Fs.ToArray(); using var matrix = Cv2.GetPerspectiveTransform(srcPoints, dstPoints); using var dst = new Mat(new Size(640, 480), MatType.CV_8UC3); Cv2.WarpPerspective(OriginalImage, dst, matrix, dst.Size()); using var dsts = new Window("dst", dst); point2Fs.Clear(); } } }
/// <summary> /// 鼠标点击事件 /// </summary> private void img_MouseDown(MouseEventTypes @event, int x, int y, MouseEventFlags flags, IntPtr userData) { if (@event.ToString().Equals("LButtonDown")) { int y0 = y - 40; int x0 = x - 40; int x1 = x0 + 80; int y1 = y0 + 80; //MessageBox.Show(x.ToString()); OpenCvSharp.Point p0 = new OpenCvSharp.Point(x0, y0); OpenCvSharp.Point p1 = new OpenCvSharp.Point(x1, y1); getMask(p0, p1, peopleList[nowIndex]); //Cv2.Rectangle(img, p0, p1,Scalar.Red); //Cv2.ImShow("chosenImg", img); Cv2.WaitKey(0); //Cv2.DestroyWindow("chosenImg"); } }
private void CallbackOpenCVAnnotate(MouseEventTypes e, int x, int y, MouseEventFlags flags, IntPtr userdata) { if (e == MouseEventTypes.LButtonDown) { Debug.WriteLine(x + "," + y + " Down"); } else if (flags.HasFlag(MouseEventFlags.LButton)) { Debug.WriteLine(x + "," + y + " flags"); } else if (e == MouseEventTypes.LButtonUp) { Debug.WriteLine(x + "," + y + " Up"); } else if (e == MouseEventTypes.MouseWheel) { Debug.WriteLine(x + "," + y + " Wheel"); } }
static void onMouse(MouseEventTypes @event, int x, int y, MouseEventFlags flags, IntPtr userData) { switch (@event) { case OpenCvSharp.MouseEventTypes.LButtonDown: { originRect = new OpenCvSharp.Point(x, y); selectInProgress = true; break; } case OpenCvSharp.MouseEventTypes.LButtonUp: { selectInProgress = false; break; } case OpenCvSharp.MouseEventTypes.RButtonDown: { //Reset selection selectInProgress = false; selectionRect = new sl.Rect(); selectionRect.x = 0; selectionRect.y = 0; selectionRect.width = 0; selectionRect.height = 0; break; } } if (selectInProgress) { selectionRect.x = Math.Min(x, originRect.X); selectionRect.y = Math.Min(y, originRect.Y); selectionRect.width = Math.Abs(x - originRect.X) + 1; selectionRect.height = Math.Abs(y - originRect.Y) + 1; } }
/// <summary> /// Gets the mouse-wheel motion delta, when handling mouse-wheel events cv::EVENT_MOUSEWHEEL and cv::EVENT_MOUSEHWHEEL. /// /// For regular mice with a scroll-wheel, delta will be a multiple of 120. The value 120 corresponds to /// a one notch rotation of the wheel or the threshold for action to be taken and one such action should /// occur for each delta.Some high-precision mice with higher-resolution freely-rotating wheels may /// generate smaller values. /// /// For cv::EVENT_MOUSEWHEEL positive and negative values mean forward and backward scrolling, /// respectively.For cv::EVENT_MOUSEHWHEEL, where available, positive and negative values mean right and /// left scrolling, respectively. /// </summary> /// <param name="flags">The mouse callback flags parameter.</param> /// <returns></returns> public static int GetMouseWheelDelta(MouseEventTypes flags) { NativeMethods.HandleException( NativeMethods.highgui_getMouseWheelDelta((int)flags, out var ret)); return(ret); }