\brief OCVDNNDetector::ParseRFDETR \param crop \param detections \param tmpRegions
| 882 | /// \param tmpRegions |
| 883 | /// |
| 884 | void OCVDNNDetector::ParseRFDETR(const cv::Rect& crop, std::vector<cv::Mat>& detections, regions_t& tmpRegions) |
| 885 | { |
| 886 | int rows = detections[0].size[1]; |
| 887 | int dimensionsDets = detections[0].size[2]; |
| 888 | int dimensionsLabels = detections[1].size[2]; |
| 889 | |
| 890 | //0: name: input, size : 1x3x560x560 |
| 891 | //1: name: dets, size : 1x300x4 |
| 892 | //2: name: labels, size : 1x300x91 |
| 893 | |
| 894 | float* dets = (float*)detections[0].data; |
| 895 | float* labels = (float*)detections[1].data; |
| 896 | |
| 897 | float x_factor = crop.width / static_cast<float>(m_inWidth); |
| 898 | float y_factor = crop.height / static_cast<float>(m_inHeight); |
| 899 | |
| 900 | auto L2Conf = [](float v) |
| 901 | { |
| 902 | return 1.f / (1.f + std::exp(-v)); |
| 903 | }; |
| 904 | |
| 905 | for (int i = 0; i < rows; ++i) |
| 906 | { |
| 907 | float maxClassScore = L2Conf(labels[0]); |
| 908 | size_t classId = 0; |
| 909 | for (size_t cli = 1; cli < static_cast<size_t>(dimensionsLabels); ++cli) |
| 910 | { |
| 911 | auto conf = L2Conf(labels[cli]); |
| 912 | if (maxClassScore < conf) |
| 913 | { |
| 914 | maxClassScore = conf; |
| 915 | classId = cli; |
| 916 | } |
| 917 | } |
| 918 | if (classId > 0) |
| 919 | --classId; |
| 920 | |
| 921 | if (maxClassScore > m_confidenceThreshold) |
| 922 | { |
| 923 | float x = dets[0]; |
| 924 | float y = dets[1]; |
| 925 | float w = dets[2]; |
| 926 | float h = dets[3]; |
| 927 | |
| 928 | int left = cvRound((x - 0.5f * w) * x_factor); |
| 929 | int top = cvRound((y - 0.5f * h) * y_factor); |
| 930 | |
| 931 | int width = cvRound(w * x_factor); |
| 932 | int height = cvRound(h * y_factor); |
| 933 | |
| 934 | if (m_classesWhiteList.empty() || m_classesWhiteList.find(T2T(classId)) != std::end(m_classesWhiteList)) |
| 935 | tmpRegions.emplace_back(cv::Rect(left + crop.x, top + crop.y, width, height), T2T(classId), static_cast<float>(maxClassScore)); |
| 936 | } |
| 937 | dets += dimensionsDets; |
| 938 | labels += dimensionsLabels; |
| 939 | } |
| 940 | } |
| 941 |