1

I have a trained model for yolo4 for object detection (.weights and .cfg) and a input image to process. The goal of the software is to scan the image with the model, draw a box around the detected object and save it as a image file (e.G. output.jpg, original Image with additional lines around the detected objects) I have found untill now no way to do it, there are some examples that create a graphical window to display the match (This does not helps me).

Has anyone experience with this?

my golang code so far:

package main

import (
    "image"
    "fmt"
    "gocv.io/x/gocv"
)

const OUT_PATH string = "/home/user"
func main() {

    imagePath   := "/home/user/test.jpg"
    netmodel    := "/home/user/yolov4-uic_last.weights"
    netconfig   := "/home/user/yolov4-uic.cfg"
    net := gocv.ReadNet(netmodel, netconfig)
    if net.Empty() {
        fmt.Printf("Error reading network model from : %v %v\n", netmodel, netconfig)
        return
    }

    defer net.Close()

    frame := gocv.IMRead(imagePath, gocv.IMReadColor)

    imgBlob := gocv.BlobFromImage(frame, 1.0, image.Pt(640, 480), gocv.NewScalar(0, 0, 0, 0), true, false)

    net.SetInput(imgBlob, "")
    prob := net.Forward("")
    
    s := prob.Size()
    fmt.Print( " size =", s , "\n")
    nparts, h := s[0], s[1]

    fmt.Print( " nparts =", nparts, "\n")
    fmt.Print( " h =", h, "\n")

// ToDo: Indicate any found Objects 
// Save Image with box around found objects

}
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87

0 Answers0