访问 4 维 cv::Mat 中的元素

时间:2021-01-16 03:13:42

标签: c++ opencv mobilenet

我开始使用 C++ 使用 OpenCV
我想使用 OpenCV 和 MobileNetSSD 模型制作一个简单的汽车检测器
用这个代码

cv::Mat frame;
/*...*/
bool bSuccess = cap.read(frame);
/*...*/
auto blob = cv::dnn::blobFromImage(frame, 1.0 / 255, cv::Size(300, 300), cv::Scalar(127.5));
net.setInput(blob);
auto out = net.forward();

我得到了 4 维 cv::Mat out 对象(大小为 1x1x100x7)。要访问模型预测,我可以在 Python 上编写此代码:

confidence = out[0, 0, i, 2]
class_id = int(out[0, 0, i, 1])

x_left_bottom = int(out[0, 0, i, 3] * cols)
y_left_bottom = int(out[0, 0, i, 4] * rows)
x_right_top = int(out[0, 0, i, 5] * cols)
y_right_top = int(out[0, 0, i, 6] * rows)

如何使用 cv::Mat 对象在 C++ 上编写相同的代码?提前致谢

0 个答案:

没有答案
相关问题