gocv
gocv copied to clipboard
PeopleDetection not working on Linux
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
orenv.cmd
script before trying togo run
orgo build
? No
Also tested with OpenCV 4.2, same problem.
I’m also hitting this issue on Ubuntu 18.04, go 1.14.2, gocv 0.23 and OpenCV 4.3.0.
The same problem inside a docker container FROM golang:1.19.2
Same problem in docker FROM gocv/opencv:4.8.1-ubuntu-22.04