java - 在 OpenCV 和 Java 中检索 R-CNN 掩码
问题描述
我正在使用 R-CNN 来检索已识别对象的掩码。
String modelWeights="frozen_inference_graph.pb";
String textGraph="mask_rcnn_inception_v2_coco_2018_01_28.pbtxt";
Net net = Dnn.readNetFromTensorflow(modelWeights, textGraph);
net.setPreferableBackend(Dnn.DNN_BACKEND_OPENCV);
net.setPreferableTarget(Dnn.DNN_TARGET_CPU);`
找到对象的边界框并可以显示
java.util.List<Mat> result = new java.util.ArrayList<Mat>(3);
java.util.List<java.lang.String> outBlobNames = new ArrayList();
outBlobNames.add("detection_out_final");
outBlobNames.add("detection_masks");
net.forward(result, outBlobNames);
根据 Using Java with OpenCV and Mask_RCNN - 堆栈内存溢出,我通过以下方式检索掩码:
Mat numClasses = result.get(0);
numClasses = numClasses.reshape(1, (int)numClasses.total() / 7);
Mat numMasks = result.get(1);
numMasks = numMasks.reshape(1, (int)numMasks.total() / 90);
Mat reshape = numMasks.reshape(1, (int) (numMasks.total() / (15 * 15)));
要绘制蒙版,我使用以下代码:
reshape.convertTo(reshape,CV_8UC3);
List<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();
Imgproc.findContours(reshape,contours,hierarchy,Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
for (int i = 0; i < contours.size(); i++) {
Scalar color = new Scalar(125);
Imgproc.drawContours(reshape, contours, i, color, 2, 1, hierarchy, 0, new Point());
}
结果,我得到了超过 14000 个轮廓,但没有正确的结果。这真的是正确的方法吗?如何选择某个找到的对象?
解决方案
推荐阅读
- jquery - ASP.NET Core MVC 中的 JQuery.post() 方法
- google-sheets - 根据时间块绘制值图表
- python - Python - 带有测试用例的银行项目
- java - 为什么 setPriority 方法设置的 newPriority 不传递给 newPriority 变量?
- mysql - Laravel Sql 查询 groupBy 和 Order
- android - 添加 Date TypeConverter 导致 Room 无法存储 API 结果
- python - 可视化神经网络架构
- git - git rm 和 git restore 有什么区别?
- html - Fullcalendar 事件侵入周视图的底行
- c++ - 甚至在执行 `main()` 的第一行并且没有非局部变量之前出现分段错误