robocar-road/cmd/road-debug/road-debug.go

66 lines
1.3 KiB
Go

package main
import (
"flag"
"github.com/cyrilix/robocar-road/road"
"go.uber.org/zap"
"gocv.io/x/gocv"
"image"
"image/color"
"log"
"os"
)
func main() {
var imgName string
flag.StringVar(&imgName, "image", "", "path to image file")
logLevel := zap.LevelFlag("log", zap.InfoLevel, "log level")
flag.Parse()
if imgName == "" {
zap.S().Errorf("bad image value")
flag.PrintDefaults()
os.Exit(1)
}
if len(os.Args) <= 1 {
flag.PrintDefaults()
os.Exit(1)
}
config := zap.NewDevelopmentConfig()
config.Level = zap.NewAtomicLevelAt(*logLevel)
lgr, err := config.Build()
if err != nil {
log.Fatalf("unable to init logger: %v", err)
}
defer func() {
if err := lgr.Sync(); err != nil {
log.Printf("unable to Sync logger: %v\n", err)
}
}()
zap.ReplaceGlobals(lgr)
d := road.NewDetector(160, 120)
img := gocv.IMRead(imgName, gocv.IMReadColor)
defer func(img *gocv.Mat) {
err := img.Close()
if err != nil {
zap.S().Warnf("unable to close image: %v", err)
}
}(&img)
if img.Empty() {
zap.S().Errorf("image %s is not a valid image", imgName)
os.Exit(1)
}
roadLimits := d.Detect(&img)
gocv.FillPoly(&img, gocv.NewPointsVectorFromPoints([][]image.Point{roadLimits}), color.RGBA{0, 0, 255, 128})
window := gocv.NewWindow("Road")
window.IMShow(img)
window.WaitKey(0)
}