Exemple #1
0
func main() {
	flag.Usage = usage
	flag.Parse()
	if flag.NArg() != 2 {
		flag.Usage()
		os.Exit(1)
	}

	var (
		imgFile = flag.Arg(0)
		visFile = flag.Arg(1)
	)

	img, err := loadImage(imgFile)
	if err != nil {
		log.Fatalln(err)
	}

	const r = 1.5
	seq := imgpyr.Sequence(1, 1/r, 0.2)
	pyr := imgpyr.New(img, seq)

	vis := pyr.Visualize()
	if err := saveImage(visFile, vis); err != nil {
		log.Fatalln(err)
	}
}
Exemple #2
0
func main() {
	flag.Usage = usage
	flag.Parse()

	// Read other arguments.
	if flag.NArg() != 3 {
		flag.Usage()
		os.Exit(1)
	}
	var (
		imgFile     = flag.Arg(0)
		weightsFile = flag.Arg(1)
		reportFile  = flag.Arg(2)
	)

	if geoStep <= 1 {
		log.Fatalln("geometric step must be greater than 1")
	}

	// Load image from file.
	img, err := loadImage(imgFile)
	if err != nil {
		log.Fatalln("could not load image:", err)
	}
	log.Println("image bounds:", img.Bounds())
	// Load weights from file.
	weights, err := loadWeights(weightsFile)
	if err != nil {
		log.Fatalln("could not load weights:", err)
	}

	log.Println("transform original image")
	// Compute feature transform of original image.
	featImg := hogImage(img, binSize)
	// Check image and detector sizes.
	if weights.Width > featImg.Width || weights.Height > featImg.Height {
		log.Fatalln("detector larger than feature image")
	}
	// Plan pyramid levels.
	minXScale := float64(weights.Width) / float64(featImg.Width)
	minYScale := float64(weights.Height) / float64(featImg.Height)
	minScale := math.Max(minXScale, minYScale)
	// Construct pyramid.
	seq := imgpyr.Sequence(1, 1/geoStep, minScale)
	log.Println("number of zoom levels:", seq.Len)
	log.Println("compute pyramid")
	pyr := imgpyr.NewInterp(img, seq, resize.NearestNeighbor)

	// Transform every level of the pyramid.
	log.Println("transform each level of pyramid")
	featImgs := make([]cv.RealVectorImage, len(pyr.Levels))
	for i, lvl := range pyr.Levels {
		featImgs[i] = hogImage(lvl, binSize)
	}

	// Run detector on every level of the pyramid.
	log.Println("search each level of pyramid")
	scores := make([]cv.RealImage, len(pyr.Levels))
	for i, featImg := range featImgs {
		scores[i] = slide.CorrelateVectorImages(featImg, weights)
	}

	// Get detections.
	log.Println("non-maxima suppression")
	dets := nonMaxSupp(scores, pyr.Scales, weights.ImageSize(), 0.5)

	// Generate report.
	report(reportFile, pyr, dets, weights.ImageSize(), scores, binSize)
}