微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 Caffe、OpenCV 和 C# 的 CNN 分割

如何解决使用 Caffe、OpenCV 和 C# 的 CNN 分割

我有一个 C# 项目需要使用图像分割。我主要从 pyimagesearch.com 学习了 DNN 和 OpenCV(感谢 Adrian!很棒的网站!)但是,我不明白我应该如何从结果中提取单个片段。 下面是python中的部分代码

ORDER BY

我能够创建网络,加载 .caffemodel,创建 blob 并运行“forward()”但我不知道如何编写等效的

blob = cv2.dnn.blobFromImage(frame,1 / 255.0,(1024,512),swapRB=True,crop=False)
net.setInput(blob)
start = time.time()
output = net.forward()
end = time.time()
# infer the total number of classes along with the spatial
# dimensions of the mask image via the shape of the output array
(numClasses,height,width) = output.shape[1:4]
# our output class ID map will be num_classes x height x width in
# size,so we take the argmax to find the class label with the
# largest probability for each and every (x,y)-coordinate in the
# image
classMap = np.argmax(output[0],axis=0)
# given the class ID map,we can map each of the class IDs to its
# corresponding color
mask = COLORS[classMap]
# resize the mask such that its dimensions match the original size
# of the input frame
mask = cv2.resize(mask,(frame.shape[1],frame.shape[0]),interpolation=cv2.INTER_NEAREST)
# perform a weighted combination of the input frame with the mask
# to form an output visualization
output = ((0.3 * frame) + (0.7 * mask)).astype("uint8")

在 C# 中(我在 OpenCV 中使用 EMGU 包装器)

这是我的代码

(numClasses,width) = output.shape[1:4]
classMap = np.argmax(output[0],axis=0)
mask = COLORS[classMap]

它只显示宽的黑色矩形。 在此先感谢您的帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。