can you comment this code: void setInstanceSegmentationPolygons( const tc::segmaskt&…
- User
can you comment this code:
void setInstanceSegmentationPolygons(
const tc::segmask_t& segMask, const tc::size_i& frameSize, const std::shared_ptric::BackendInfo& backendInfo, std::vectortc::detection_t& output) { const auto [h, w, c] = backendInfo->getModelNetworkParams(backendInfo->getModelId(ic::BackendInfo::Model::Type::Bed)).imgSize; std::vector padsize = utils::getYoloSegPadSize(h,w,frameSize); const int segWidth = segMask.segShapes[2]; const int segHeight = segMask.segShapes[3]; const int segChannels = segMask.segShapes[1]; cv::Mat maskProposals; for (int i = 0; i < segMask.raw_mask_proposals.size(); ++i) maskProposals.push_back( cv::Mat(segMask.raw_mask_proposals[i]).t() );cv::Mat protos = cv::Mat(segMask.raw_mask_protos).reshape(0, {segChannels, segWidth * segHeight }); if(maskProposals.empty()) return std::vector<tc::polygon_i>{}; if(protos.empty()) return std::vector<tc::polygon_i>{}; cv::Mat matmulRes = (maskProposals * protos).t(); cv::Mat masks = matmulRes.reshape(output.size(), { segWidth, segHeight }); std::vector<cv::Mat> maskChannels; split(masks, maskChannels); for (int i = 0; i < output.size(); ++i) { cv::Mat dest, mask; //sigmoid cv::exp(-maskChannels[i], dest); dest = 1.0f / (1.0f + dest);//160*160 int newh = padsize[0], neww = padsize[1], padh = padsize[2], padw = padsize[3]; const float MASK_THRESHOLD = 0.5f; cv::Rect roi(int((float)padw / w * segWidth), int((float)padh / h * segHeight), int(segWidth - padw / 2), int(segHeight - padh / 2)); dest = dest(roi); cv::Rect temp_rect = tcToCvRect(output[i].bbox); const cv::Size cvFrameSize(frameSize.width, frameSize.height); resize(dest, mask, cvFrameSize, cv::INTER_NEAREST); mask = mask(temp_rect) > MASK_THRESHOLD; cv::Mat black(cvFrameSize, CV_8UC3, cv::Scalar(0, 0, 0)); black(temp_rect).setTo(cv::Scalar(255, 0, 0), mask); cv::cvtColor(black, black, cv::COLOR_BGR2GRAY); auto c = findBiggestContour(black); std::vector<cv::Point> hull(c.size()); cv::convexHull(c, hull); tc::polygon_i outPolygon; for (auto&& h : hull) { outPolygon.insert(tc::point_i(h.x, h.y)); } output[i].polygon = outPolygon; }}
- Assistant
This code defines a function called
setInstanceSegmentationPolygons. The function is used to compute the instance segmentation polygons for an input set of object detections. The function takes in four arguments:segMask: a tensor containing segmentation mask information.frameSize: the size (height and width) of the input video frame.backendInfo: a shared pointer to the backend information object, which contains necessary information about the model used for object detection and segmentation.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.