From f96e80c61ebfdff28b835a396b69fc3aa222afb8 Mon Sep 17 00:00:00 2001 From: DongHyun Kim Date: Sun, 3 May 2020 01:31:07 +0900 Subject: [PATCH] fix create CV32F Image, before blobImage --- cmd/caffe-classifier/main.go | 6 +++++- cmd/dnn-detection/main.go | 6 +++++- cmd/dnn-style-transfer/main.go | 6 +++++- cmd/ssd-facedetect/main.go | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/caffe-classifier/main.go b/cmd/caffe-classifier/main.go index be359d3a..2ca10e6d 100644 --- a/cmd/caffe-classifier/main.go +++ b/cmd/caffe-classifier/main.go @@ -98,8 +98,12 @@ func main() { continue } + // convert image Mat DataType to CV_32F + img_CV32F := img.Clone() + img_CV32F.ConvertTo(&img_CV32F, gocv.MatTypeCV32F) + // convert image Mat to 224x224 blob that the classifier can analyze - blob := gocv.BlobFromImage(img, 1.0, image.Pt(224, 224), gocv.NewScalar(104, 117, 123, 0), false, false) + blob := gocv.BlobFromImage(img_CV32F, 1.0, image.Pt(224, 224), gocv.NewScalar(104, 117, 123, 0), false, false) // feed the blob into the classifier net.SetInput(blob, "") diff --git a/cmd/dnn-detection/main.go b/cmd/dnn-detection/main.go index 24d8426f..3a5ec497 100644 --- a/cmd/dnn-detection/main.go +++ b/cmd/dnn-detection/main.go @@ -107,8 +107,12 @@ func main() { continue } + // convert image Mat DataType to CV_32F + img_CV32F := img.Clone() + img_CV32F.ConvertTo(&img_CV32F, gocv.MatTypeCV32F) + // convert image Mat to 300x300 blob that the object detector can analyze - blob := gocv.BlobFromImage(img, ratio, image.Pt(300, 300), mean, swapRGB, false) + blob := gocv.BlobFromImage(img_CV32F, ratio, image.Pt(300, 300), mean, swapRGB, false) // feed the blob into the detector net.SetInput(blob, "") diff --git a/cmd/dnn-style-transfer/main.go b/cmd/dnn-style-transfer/main.go index 98c81cb9..f9ae753a 100644 --- a/cmd/dnn-style-transfer/main.go +++ b/cmd/dnn-style-transfer/main.go @@ -78,8 +78,12 @@ func main() { continue } + // convert image Mat DataType to CV_32F + img_CV32F := img.Clone() + img_CV32F.ConvertTo(&img_CV32F, gocv.MatTypeCV32F) + // convert image Mat to 640x480 blob that the style transfer can analyze - blob := gocv.BlobFromImage(img, 1.0, image.Pt(640, 480), gocv.NewScalar(103.939, 116.779, 123.68, 0), false, false) + blob := gocv.BlobFromImage(img_CV32F, 1.0, image.Pt(640, 480), gocv.NewScalar(103.939, 116.779, 123.68, 0), false, false) // feed the blob into the detector net.SetInput(blob, "") diff --git a/cmd/ssd-facedetect/main.go b/cmd/ssd-facedetect/main.go index 6819db52..78d9a511 100644 --- a/cmd/ssd-facedetect/main.go +++ b/cmd/ssd-facedetect/main.go @@ -88,8 +88,12 @@ func main() { W := float32(img.Cols()) H := float32(img.Rows()) + // convert image Mat DataType to CV_32F + img_CV32F := img.Clone() + img_CV32F.ConvertTo(&img_CV32F, gocv.MatTypeCV32F) + // convert image Mat to 96x128 blob that the detector can analyze - blob := gocv.BlobFromImage(img, 1.0, image.Pt(128, 96), gocv.NewScalar(104.0, 177.0, 123.0, 0), false, false) + blob := gocv.BlobFromImage(img_CV32F, 1.0, image.Pt(300, 300), gocv.NewScalar(104.0, 177.0, 123.0, 0), false, false) defer blob.Close() // feed the blob into the classifier