add Crop() sample code.
This commit is contained in:
parent
71e2e0317e
commit
1f95ef5787
1 changed files with 29 additions and 0 deletions
29
samples/crop.go
Normal file
29
samples/crop.go
Normal file
|
|
@ -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)
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue