public CreateTrackbar2 ( string name, int value, int max, CvTrackbarCallback2 callback, object userdata ) : OpenCvSharp.CvTrackbar | ||
name | string | Name of created trackbar. |
value | int | The position of the slider |
max | int | Maximal position of the slider. Minimal position is always 0. |
callback | CvTrackbarCallback2 | the function to be called every time the slider changes the position. This function should be prototyped as void Foo(int); |
userdata | object | |
return | OpenCvSharp.CvTrackbar |
public CvTrackbar CreateTrackbar2(string name, int value, int max, CvTrackbarCallback2 callback, object userdata)
{
CvTrackbar trackbar = new CvTrackbar(name, this.name, value, max, callback, userdata);
trackbars.Add(name, trackbar);
return trackbar;
}
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()); }