\brief OCVDNNDetector::ParseRFDETR_IS \param crop \param detections \param tmpRegions
| 946 | /// \param tmpRegions |
| 947 | /// |
| 948 | void OCVDNNDetector::ParseRFDETR_IS(const cv::Rect& crop, std::vector<cv::Mat>& detections, regions_t& tmpRegions) |
| 949 | { |
| 950 | int rows = detections[0].size[1]; |
| 951 | int dimensionsDets = detections[0].size[2]; |
| 952 | int dimensionsLabels = detections[1].size[2]; |
| 953 | |
| 954 | //0: name: input, size : 1x3x560x560 |
| 955 | //1: name: dets, size : 1x300x4 |
| 956 | //2: name: labels, size : 1x300x91 |
| 957 | |
| 958 | float* dets = (float*)detections[0].data; |
| 959 | float* labels = (float*)detections[1].data; |
| 960 | |
| 961 | float x_factor = crop.width / static_cast<float>(m_inWidth); |
| 962 | float y_factor = crop.height / static_cast<float>(m_inHeight); |
| 963 | |
| 964 | auto L2Conf = [](float v) |
| 965 | { |
| 966 | return 1.f / (1.f + std::exp(-v)); |
| 967 | }; |
| 968 | |
| 969 | for (int i = 0; i < rows; ++i) |
| 970 | { |
| 971 | float maxClassScore = L2Conf(labels[0]); |
| 972 | size_t classId = 0; |
| 973 | for (size_t cli = 1; cli < static_cast<size_t>(dimensionsLabels); ++cli) |
| 974 | { |
| 975 | auto conf = L2Conf(labels[cli]); |
| 976 | if (maxClassScore < conf) |
| 977 | { |
| 978 | maxClassScore = conf; |
| 979 | classId = cli; |
| 980 | } |
| 981 | } |
| 982 | if (classId > 0) |
| 983 | --classId; |
| 984 | |
| 985 | if (maxClassScore > m_confidenceThreshold) |
| 986 | { |
| 987 | float x = dets[0]; |
| 988 | float y = dets[1]; |
| 989 | float w = dets[2]; |
| 990 | float h = dets[3]; |
| 991 | |
| 992 | int left = cvRound((x - 0.5f * w) * x_factor); |
| 993 | int top = cvRound((y - 0.5f * h) * y_factor); |
| 994 | |
| 995 | int width = cvRound(w * x_factor); |
| 996 | int height = cvRound(h * y_factor); |
| 997 | |
| 998 | if (m_classesWhiteList.empty() || m_classesWhiteList.find(T2T(classId)) != std::end(m_classesWhiteList)) |
| 999 | tmpRegions.emplace_back(cv::Rect(left + crop.x, top + crop.y, width, height), T2T(classId), static_cast<float>(maxClassScore)); |
| 1000 | } |
| 1001 | dets += dimensionsDets; |
| 1002 | labels += dimensionsLabels; |
| 1003 | } |
| 1004 | } |
| 1005 |