Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detector.cpp #5

Open
zhihenan opened this issue Jan 21, 2021 · 4 comments
Open

detector.cpp #5

zhihenan opened this issue Jan 21, 2021 · 4 comments

Comments

@zhihenan
Copy link

您好,请问一下如何在detector.cpp中获取到识别结果的类别信息呢?

@YONGHUICAI
Copy link

您好,请问一下如何在detector.cpp中获取到识别结果的类别信息呢?

我是这么实现的:

  1. 首先给parse_yolov5函数增加一个vector容器存放类别信息,如bool Detector::parse_yolov5(const Blob::Ptr &blob,int net_grid,float cof_threshold, vector& o_rect,vector& o_rect_cof, vector& classIds)
  2. 接着在detector.cpp中的第57行后增加一行代码,即把类别序号push进类别的容器类,如classIds.push_back(idx-5)
  3. 在detector.cpp的第132行增加一个vector classIds; 然后把137行的双引号改成classIds[final[i]]
  4. 修改detector.h文件中第18行的std::string name成int class_id
  5. 最后在main.cpp的43行后可以把类别序号打印出来了:std::cout << detected_objects[i].class_id << std::enl;或者使用cv::putText函数把类别序号对应的类别打印在目标的上方,先在main.cpp文件第2行把coco的类别英文名定义好,如const std::string class_name[80] = {"person", "bicycle", "car", ......},然后在44行添加cv::putText(osrc, class_name[detected_objects[i].class_id] + ": " +std::to_string(detected_objects[i].prob), cv::Point(xmin, ymin-1), cv::FONT_HERSHEY_PLAIN, 1, cv::scalar(0x00, 0xFF, 0x00), 1.5);

当然你可以把classIds先直接映射会coco的类别名先,就不用修改detetor.h文件中的结构体了,以上是根据我的需求改的。

@zhihenan
Copy link
Author

谢谢您的回答,问题解决了。

@xingye666
Copy link

xingye666 commented Apr 14, 2022

我的出现了段错误,
第一步 vector& classIds,类型是int吗
第三步 132 行vector classIds;类型是vector < int >吗
类型请大神指点一下
我这样写是哪里写错了

@xingye666
Copy link

我搞好了就是颜色看起来怪怪的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants