From 1f95ef57873df1b7a8e1c58f3701ed24d54de2bb Mon Sep 17 00:00:00 2001 From: Vanilla Hsu Date: Mon, 29 Dec 2014 20:13:47 +0800 Subject: [PATCH] add Crop() sample code. --- samples/crop.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 samples/crop.go diff --git a/samples/crop.go b/samples/crop.go new file mode 100644 index 0000000..62a1849 --- /dev/null +++ b/samples/crop.go @@ -0,0 +1,29 @@ +package main + +import ( + "os" + "path" + "runtime" + + opencv "github.com/vanillahsu/go-opencv/opencv" +) + +func main() { + _, currentfile, _, _ := runtime.Caller(0) + filename := path.Join(path.Dir(currentfile), "../images/lena.jpg") + if len(os.Args) == 2 { + filename = os.Args[1] + } + + image := opencv.LoadImage(filename) + if image == nil { + panic("LoadImage fail") + } + defer image.Release() + + crop := opencv.Crop(image, 0, 0, 50, 50) + opencv.SaveImage("/tmp/crop.jpg", crop, 0) + crop.Release() + + os.Exit(0) +}