如何将图像转换为Golang的张量?
我正在尝试将此python接口转换为tensorflow服务到Golang:
image = cv2.imread("1.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (256, 256))
image = np.expand_dims(image, axis=0)
image = np.true_divide(image, 255)
np.shape(image)
我想到的是:
Package Main
import (
"log"
"image"
"gocv.io/x/gocv"
)
func main() {
imageFilePath := "./a.jpg"
mat := gocv.IMRead(imageFilePath, gocv.IMReadAnyColor)
if mat.Empty() {
log.Panic("Can not read Image file : ", imageFilePath)
return
}
resizeImage := gocv.NewMat()
gocv.Resize(mat, &resizeImage, image.Point{X: 256, Y: 256}, 0, 0, gocv.InterpolationNearestNeighbor)
img := resizeImage.Clone()
gocv.CvtColor(resizeImage, &img, gocv.ColorBGRToRGB)
// equivalent to np.expand_dims(image, axis=0) ?
}
,我尝试从 gonum ,但没有运气将其插入GOCV,所以我毫无头绪,感谢您对此的帮助。
I'm trying to convert this python interface to tensorflow serving into golang:
image = cv2.imread("1.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (256, 256))
image = np.expand_dims(image, axis=0)
image = np.true_divide(image, 255)
np.shape(image)
What I'm came up with is:
package main
import (
"log"
"image"
"gocv.io/x/gocv"
)
func main() {
imageFilePath := "./a.jpg"
mat := gocv.IMRead(imageFilePath, gocv.IMReadAnyColor)
if mat.Empty() {
log.Panic("Can not read Image file : ", imageFilePath)
return
}
resizeImage := gocv.NewMat()
gocv.Resize(mat, &resizeImage, image.Point{X: 256, Y: 256}, 0, 0, gocv.InterpolationNearestNeighbor)
img := resizeImage.Clone()
gocv.CvtColor(resizeImage, &img, gocv.ColorBGRToRGB)
// equivalent to np.expand_dims(image, axis=0) ?
}
I've tried to get help from gonum but had no luck plugging it to gocv, so I'm left clueless and appreciate your help about this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论