微信公众号:OpenCV学堂
关注获取更多计算机视觉与深度学习知识
引言
对比与原因查找
for (int i = 0; i < det_output.rows; i++) {
cv::Mat classes_scores = det_output.row(i).colRange(4, 4 + nClasses);
cv::Point classIdPoint;
double score;
minMaxLoc(classes_scores, 0, & score, 0, & classIdPoint);
// 置信度 0~1之间
if (score > this -> score_threshold) {
float cx = det_output.at<float>(i, 0);
float cy = det_output.at<float>(i, 1);
float ow = det_output.at<float>(i, 2);
float oh = det_output.at<float>(i, 3);
int x = static_cast<int>((cx - 0.5 * ow) * xy_factor);
int y = static_cast<int>((cy - 0.5 * oh) * xy_factor);
int width = static_cast<int>(ow * xy_factor);
int height = static_cast<int>(oh * xy_factor);
for (int i = 0; i < det_output.rows; i++) {
auto rowPtr = det_output.row(i).ptr<float>();
auto bboxesPtr = rowPtr;
auto scoresPtr = rowPtr + 4;
auto maxSPtr = std::max_element(scoresPtr, scoresPtr + numClasses);
float score = *maxSPtr;
// 置信度 0~1之间
if (score > this->score_t)
{
float cx = *bboxesPtr++;
float cy = *bboxesPtr++;
float ow = *bboxesPtr++;
float oh = *bboxesPtr;
int x = static_cast<int>((cx - 0.5 * ow) * rate_xy);
int y = static_cast<int>((cy - 0.5 * oh) * rate_xy);
int width = static_cast<int>(ow * rate_xy);
int height = static_cast<int>(oh * rate_xy);
int64 start = cv::getTickCount();
for (int r = 0; r < h; r++) {
cv::Mat one_row = dst.row(r).colRange(0, w);
cv::Point classIdPoint;
double score;
minMaxLoc(one_row, 0, &score, 0, &classIdPoint);
//std::cout << "max value: " << score << std::endl;
}
float t = (cv::getTickCount() - start) / static_cast<float>(cv::getTickFrequency());
std::cout << " run time: " << t * 1000 << " ms " << std::endl;
int64 start = cv::getTickCount();
for (int r = 0; r < h; r++) {
auto rowPtr = dst.row(r).ptr
(); auto maxSPtr = std::max_element(rowPtr, rowPtr + w);
float score = *maxSPtr;
//std::cout << "max value: " << score << std::endl;
}
float t = (cv::getTickCount() - start) / static_cast
(cv::getTickFrequency()); std::cout << " std::max run time: " << t * 1000 << " ms " << std::endl;
执行时间为:
OpenCV4系统化学习
推荐阅读
OpenCV4.8+YOLOv8对象检测C++推理演示
ZXING+OpenCV打造开源条码检测应用
攻略 | 学习深度学习只需要三个月的好方法
三行代码实现 TensorRT8.6 C++ 深度学习模型部署
实战 | YOLOv8+OpenCV 实现DM码定位检测与解析
对象检测边界框损失 – 从IOU到ProbIOU
初学者必看 | 学习深度学习的五个误区