使用 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 (将#修改为@)