| 247 | } |
| 248 | |
| 249 | void show_bbox(cv::Mat image, torch::Tensor bboxes, std::vector<std::string> name_list) { |
| 250 | //���û����ı�����ز��� |
| 251 | int font_face = cv::FONT_HERSHEY_COMPLEX; |
| 252 | double font_scale = 0.4; |
| 253 | int thickness = 1; |
| 254 | float* bbox = new float[bboxes.size(0)](); |
| 255 | std::cout << bboxes << std::endl; |
| 256 | if (bboxes.equal(torch::zeros_like(bboxes))) return; |
| 257 | memcpy(bbox, bboxes.cpu().data_ptr(), bboxes.size(0) * sizeof(float)); |
| 258 | for (int i = 0; i < bboxes.size(0); i = i + 7) |
| 259 | { |
| 260 | 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)); |
| 261 | //���ı�����л��� |
| 262 | cv::Point origin; |
| 263 | origin.x = bbox[i + 0]; |
| 264 | origin.y = bbox[i + 1] + 8; |
| 265 | cv::putText(image, name_list[bbox[i + 6]], origin, font_face, font_scale, cv::Scalar(0, 0, 255), thickness, 1, 0); |
| 266 | } |
| 267 | delete bbox; |
| 268 | cv::imwrite("prediction.jpg", image); |
| 269 | cv::imshow("test", image); |
| 270 | cv::waitKey(0); |
| 271 | cv::destroyAllWindows(); |
| 272 | } |
| 273 | |
| 274 | void Detector::Predict(cv::Mat image, bool show, float conf_thresh, float nms_thresh) { |
| 275 | int origin_width = image.cols; |