MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / show_bbox_coco

Function show_bbox_coco

lesson7-Detection/src/main.cpp:6–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include"Detector.h"
5
6void show_bbox_coco(cv::Mat image, torch::Tensor bboxes, int nums) {
7 //���û����ı�����ز���
8 int font_face = cv::FONT_HERSHEY_COMPLEX;
9 double font_scale = 0.4;
10 int thickness = 1;
11 float* bbox = new float[bboxes.size(0)]();
12 std::cout << bboxes << std::endl;
13 memcpy(bbox, bboxes.cpu().data_ptr(), bboxes.size(0) * sizeof(float));
14 for (int i = 0; i < bboxes.size(0); i = i + 7)
15 {
16 cv::rectangle(image, cv::Rect(bbox[i + 0], bbox[i + 1], bbox[i + 2] - bbox[i + 0], bbox[i + 3] - bbox[i + 1]), cv::Scalar(0, 0, 255));
17 //���ı�����л���
18 cv::Point origin;
19 origin.x = bbox[i + 0];
20 origin.y = bbox[i + 1] + 8;
21 cv::putText(image, std::to_string(int(bbox[i + 6])), origin, font_face, font_scale, cv::Scalar(0, 0, 255), thickness, 1, 0);
22 }
23 delete bbox;
24 cv::imwrite("prediction_coco.jpg", image);
25 cv::imshow("test", image);
26 cv::waitKey(0);
27 cv::destroyAllWindows();
28}
29
30void Predict(YoloBody_tiny detector, cv::Mat image, bool show, float conf_thresh, float nms_thresh) {
31 int origin_width = image.cols;

Callers 1

PredictFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected