Last active
August 29, 2015 14:17
-
-
Save 0V/b0e2c6eb8a3fa9277803 to your computer and use it in GitHub Desktop.
OpenCvSharp でお絵かきサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using OpenCvSharp; | |
using OpenCvSharp.CPlusPlus; | |
using System; | |
namespace OpenCvSharpSample.Samples | |
{ | |
public class MethodTest | |
{ | |
public static void MouseClickCanvasWindow() | |
{ | |
using (var window = new Window("canvas")) | |
{ | |
var color = new Scalar(100, 100, 0); | |
var mat = new Mat(new Size(640, 480), MatType.CV_8UC3); | |
mat.SetTo(new Scalar(255, 255, 255)); | |
window.ShowImage(mat); | |
window.OnMouseCallback += (e, x, y, flags) => | |
{ | |
if (e == MouseEvent.LButtonDown || (e == MouseEvent.MouseMove && flags == MouseEvent.FlagLButton)) | |
{ | |
mat.Circle(x, y, 1, color, 3, LineType.AntiAlias); | |
window.ShowImage(mat); | |
} | |
}; | |
bool notEscDown = true; | |
while (notEscDown) | |
{ | |
switch (Cv2.WaitKey(33)) | |
{ | |
case 3014656: //Delete #Clear | |
mat.SetTo(new Scalar(255, 255, 255)); | |
window.ShowImage(mat); | |
break; | |
case 27: //Esc #Exit | |
notEscDown = false; | |
break; | |
case 32: //SpaceBar #Save | |
mat.SaveImage(DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".jpg"); | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment