duanquan4451 2018-03-08 15:01
浏览 94

寻找GOCV的人

I worked last year with OpenCV and Python. Today I wanted to try OpenCV using Golang with the GOCV package. I just wanted a simple Python example () to evalute but in Golang. I used even the same parameters (except the hiThresh and finalThreshold, i used the default values). Somehow I cannot get it working with GOCV, he only finds one centered result.

Here is my code:

package main

import (
    "encoding/json"
    "fmt"
    "image"
    "image/color"

    "gocv.io/x/gocv"
)

func main() {

    // define default hog descriptor
    hog := gocv.NewHOGDescriptor()
    defer hog.Close()
    hog.SetSVMDetector(gocv.HOGDefaultPeopleDetector())

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

    // read image
    img := gocv.IMRead("images/person_010.bmp", 0)

    //resize image
    fact := float64(400) / float64(img.Cols())
    newY := float64(img.Rows()) * fact
    gocv.Resize(img, img, image.Point{X: 400, Y: int(newY)}, 0, 0, 1)

    // detect people in image
    rects := hog.DetectMultiScaleWithParams(img, 0, image.Point{X: 8, Y: 8}, image.Point{X: 16, Y: 16}, 1.05, 2, false)

    // print found points
    printStruct(rects)

    // draw a rectangle around each face on the original image,
    // along with text identifing as "Human"
    for _, r := range rects {
        gocv.Rectangle(img, r, blue, 3)

        size := gocv.GetTextSize("Human", gocv.FontHersheyPlain, 1.2, 2)
        pt := image.Pt(r.Min.X+(r.Min.X/2)-(size.X/2), r.Min.Y-2)
        gocv.PutText(img, "Human", pt, gocv.FontHersheyPlain, 1.2, blue, 2)
    }

    if ok := gocv.IMWrite("loool.jpg", img); !ok {
        fmt.Println("Error")
    }

}

func printStruct(i interface{}) {
    b, err := json.Marshal(i)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println(string(b))
}

Here is the input image:
input image

And here is the result:
enter image description here

  • 写回答

1条回答 默认 最新

  • duai3681 2018-03-08 20:43
    关注

    Actually, I've just run the code you posted with the image you provided—and I've got another resulting image:

    opencv result

    I'm running:

    • gocv version: 0.10.0
    • opencv lib version: 3.4.1
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行