C++实现MASK RCNN图片检测的过程中的一些代码问题。

想请问下,在opencv4.0的dnn中的object_detection.cpp代码void postprocess(Mat& frame, const vector<Mat>& outs)中的outDetections到底是一个几维的结构,每个维度的存储的信息是什么。以及reshape后的outDetections是什么东西?

void postprocess(Mat& frame, const vector<Mat>& outs)
{
	Mat outDetections = outs[0];    //这个outDetections应该是存储检测框的内容
	Mat outMasks = outs[1];  
	// Output size of masks is NxCxHxW where
	// N - number of detected boxes
	// C - number of classes (excluding background)
	// HxW - segmentation shape

	//const int nonnon = outDetections.size[1];		
	//const int nonn = outDetections.size[0];
			
	outDetections = outDetections.reshape(1, outDetections.total() / 7);  
	for (int i = 0; i < numDetections; ++i)
	{
		float score = outDetections.at<float>(i, 2);
		if (score > confThreshold)
		{
			// Extract the bounding box
			int confidence = static_cast<int>(outDetections.at<float>(i, 0));
			int classId = static_cast<int>(outDetections.at<float>(i, 1));
			int left = static_cast<int>(frame.cols * outDetections.at<float>(i, 3));
			int top = static_cast<int>(frame.rows * outDetections.at<float>(i, 4));
			int right = static_cast<int>(frame.cols * outDetections.at<float>(i, 5));
			int bottom = static_cast<int>(frame.rows * outDetections.at<float>(i, 6));

			left = max(0, min(left, frame.cols - 1));
			top = max(0, min(top, frame.rows - 1));
			right = max(0, min(right, frame.cols - 1));
			bottom = max(0, min(bottom, frame.rows - 1));
			Rect box = Rect(left, top, right - left + 1, bottom - top + 1); 
			// Extract the mask for the object  
			Mat objectMask(outMasks.size[2], outMasks.size[3], CV_32F, outMasks.ptr<float>(i, classId));
																					
			// Draw bounding box, colorize and show the mask on the image
			drawBox(frame, classId, score, box, objectMask);             
		}
	}
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值