Skip to content

Instantly share code, notes, and snippets.

@dowlingw
Created June 4, 2019 14:05
Show Gist options
  • Save dowlingw/c984def5a456b71ba5a2dd895290830e to your computer and use it in GitHub Desktop.
Save dowlingw/c984def5a456b71ba5a2dd895290830e to your computer and use it in GitHub Desktop.
gocv yolov3 troubleshooting
package main
import (
"fmt"
"gocv.io/x/gocv"
"image"
)
const vehicleWeights = "data/yolov3/yolov3.weights"
const vehicleNetcfg = "data/yolov3/yolov3.cfg"
const YOLO3_FASTEST = 320
func main() {
net := gocv.ReadNet(vehicleWeights, vehicleNetcfg)
defer net.Close()
window := gocv.NewWindow("Capture Window")
defer window.Close()
frame := gocv.IMRead("../car.jpg", gocv.IMReadColor)
blob := gocv.BlobFromImage(frame, float64(1.0/255.0), image.Pt(YOLO3_FASTEST, YOLO3_FASTEST), gocv.NewScalar(0, 0, 0, 0), false, false)
net.SetInput(blob, "data")
probs := net.ForwardLayers(getOutputsNames(&net))
postProcess(&frame, &probs)
window.IMShow(frame)
// Test code
window.WaitKey(10000000000)
}
func getOutputsNames(net *gocv.Net) []string {
var outputLayers []string
for i := range net.GetUnconnectedOutLayers() {
layer := net.GetLayer(i)
layerName := layer.GetName()
if layerName != "_input" {
outputLayers = append(outputLayers, layerName)
}
}
return outputLayers
}
func postProcess(frame *gocv.Mat, outs *[]gocv.Mat) {
fmt.Println("===")
fmt.Printf("outs = %d\n", len(*outs))
for i, out := range *outs {
fmt.Printf("i = %d\n", i)
fmt.Printf("out.Type() = %d\n", out.Type())
fmt.Printf("out.Rows() = %d\n", out.Rows())
fmt.Printf("out.Cols() = %d\n", out.Cols())
fmt.Printf("out.Size() = %d\n", out.Size())
fmt.Printf("out.Total() = %d\n", out.Total())
fmt.Printf("out.Channels() = %d\n", out.Channels())
data, _ := out.DataPtrFloat32()
fmt.Printf("len(data) = %d\n", len(data))
fmt.Println("...")
}
}
@zzy444626905
Copy link

Exception 0x20474343 0x2a60eee0 0x0 0x7ffdb6231f08
PC=0x7ffdb6231f08
signal arrived during external code execution

gocv.io/x/gocv._Cfunc_Net_BlobFromImage(0x1560ad0, 0x3f70101010101010, 0x14000000140, 0x0, 0x0, 0x0, 0x0, 0x2c980001, 0x0)
_cgo_gotypes.go:4742 +0x58
gocv.io/x/gocv.BlobFromImage.func1(0x1560ad0, 0x3f70101010101010, 0x14000000140, 0x0, 0x0, 0x0, 0x0, 0x2c980001, 0xc000088340)
E:/go/go/gopath/pkg/mod/gocv.io/x/gocv@v0.23.0/dnn.go:317 +0xc2
gocv.io/x/gocv.BlobFromImage(0x1560ad0, 0x3f70101010101010, 0x140, 0x140, 0x0, 0x0, 0x0, 0x0, 0xc000080001, 0xc0000c7f48)
E:/go/go/gopath/pkg/mod/gocv.io/x/gocv@v0.23.0/dnn.go:317 +0xa5
main.main()
E:/go/golang项目/go读取网络摄像头/main.go:23 +0x15d
rax 0xc
rbx 0x2a60eee0
rcx 0xffffffffffffff00
rdi 0x2a60ef20
rsi 0x7066d460
rbp 0x2a60ef60
rsp 0x9ff130
r8 0x342d76636e65706f
r9 0x64016d5c302e332e
r10 0x6e6e645c00000000
r11 0x1554880
r12 0x2a60ef80
r13 0x9ffae0
r14 0x0
r15 0x3f70101010101010
rip 0x7ffdb6231f08
rflags 0x202
cs 0x33
fs 0x53
gs 0x2b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment