gocv icon indicating copy to clipboard operation
gocv copied to clipboard

PeopleDetection not working on Linux

Open Lallassu opened this issue 4 years ago • 4 comments

Description

I'm trying to run the HOGDefaultPeopleDetector() on Ubuntu 19.04 and it always detect a person in the center of the image for any image. So it seems to fail to detect correctly. Example output for running on webcam without anything in front (same result with image or avi file).

[(91,22)-(163,165)]
[(91,22)-(163,165)]
[(91,22)-(163,165)]
[(91,22)-(163,165)]
[(91,22)-(163,165)]
[(91,22)-(163,165)]
[(91,22)-(163,165)]
[(91,22)-(163,165)]
[(91,22)-(163,165)]

Steps to Reproduce

Source code for the example provided below. Note that I've tried without making the image gray and also tried different conversions AND without conversion. Same result each time.

package main

import (
	"fmt"
	"image"
	"image/color"
	"os"

	"gocv.io/x/gocv"
)

func main() {
	hog := gocv.NewHOGDescriptor()
	defer hog.Close()
	hog.SetSVMDetector(gocv.HOGDefaultPeopleDetector())

	deviceID := os.Args[1]
	webcam, err := gocv.OpenVideoCapture(deviceID)
	if err != nil {
		fmt.Printf("Error opening video capture device: %v\n", deviceID)
		return
	}
	defer webcam.Close()

	// color for the rect when faces detected
	blue := color.RGBA{0, 0, 255, 0}

	img := gocv.NewMat()
	defer img.Close()

	window := gocv.NewWindow("Detection")
	defer window.Close()

	for {
		if ok := webcam.Read(&img); !ok {
			fmt.Printf("Device closed: %v\n", deviceID)
			return
		}
		if img.Empty() {
			continue
		}

		gocv.Resize(img, &img, image.Point{}, 0.4, 0.4, 1)

		gocv.CvtColor(img, &img, gocv.ColorRGBToGray)
		gocv.Threshold(img, &img, 80, 255, gocv.ThresholdBinaryInv)

		rects := hog.DetectMultiScale(img)

		fmt.Printf("%v\n", rects)

		for _, r := range rects {
			gocv.Rectangle(&img, r, blue, 1)
		}
		window.IMShow(img)

		if window.WaitKey(1) >= 0 {
			break
		}
	}
}

Your Environment

  • Operating System and version: Ubuntu 19.04
  • OpenCV version used: 3.2.0
  • How did you install OpenCV? apt
  • GoCV version used: v0.22.0
  • Go version: 1.14.1
  • Did you run the env.sh or env.cmd script before trying to go run or go build? No

Lallassu avatar Mar 24 '20 12:03 Lallassu

Also tested with OpenCV 4.2, same problem.

Lallassu avatar Mar 24 '20 14:03 Lallassu

I’m also hitting this issue on Ubuntu 18.04, go 1.14.2, gocv 0.23 and OpenCV 4.3.0.

haydenwoodhead avatar May 15 '20 05:05 haydenwoodhead

The same problem inside a docker container FROM golang:1.19.2

alxshogenov avatar Nov 11 '22 07:11 alxshogenov

Same problem in docker FROM gocv/opencv:4.8.1-ubuntu-22.04

KateFox1982 avatar Mar 25 '24 07:03 KateFox1982