c++ 代码实现将下图代码的obj.seg渲染在image上,obj.seg是yolov8预测出来的mask图, cv::Mat image = cv::imread("inference/yq.jpg"); auto yolo = yolo::load("/home/zhangyu/tensorrt_code/test/1.18-integrate-full-yolov5/workspace/last.transd.trtmodel", yolo::Type::V8Seg); if (yolo == nullptr) return; auto objs = yolo->forward(cvimg(image)); int i = 0; for (auto &obj : objs) { uint8_t b, g, r; tie(b, g, r) = yolo::random_color(obj.class_label); cv::rectangle(image, cv::Point(obj.left, obj.top), cv::Point(obj.right, obj.bottom), cv::Scalar(b, g, r), 5); auto name = cocolabels[obj.class_label]; auto caption = cv::format("%s %.2f", name, obj.confidence); int width = cv::getTextSize(caption, 0, 1, 2, nullptr).width + 10; cv::rectangle(image, cv::Point(obj.left - 3, obj.top - 33), cv::Point(obj.left + width, obj.top), cv::Scalar(b, g, r), -1); cv::putText(image, caption, cv::Point(obj.left, obj.top - 5), 0, 1, cv::Scalar::all(0), 2, 16); if (obj.seg) { // cv::imwrite(cv::format("%d_mask.jpg", i), // cv::Mat(obj.seg->height, obj.seg->width, CV_8U, obj.seg->data)); i++; } } printf("Save result to Result.jpg, %d objects\n", (int)objs.size()); cv::imwrite("Result.jpg", image); }