Repository: opencv/opencv
File: modules/dnn/src/layers/nonmaxsuppression_layer.cpp (C++)

Code before:

        outputs.assign(1, MatShape({1, 3}));
        return false;
    }

    void getTypes(const std::vector<MatType>&, const int requiredOutputs, const int requiredInternals,
                   std::vector<MatType>& outputs, std::vector<MatType>& internals) const CV_OVERRIDE {
        outputs.assign(requiredOutputs, MatType(CV_64S));
        internals.assign(requiredInternals, MatType(CV_32F));
    }

    void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays) CV_OVERRIDE {
        std::vector<Mat> inputs, outputs;
        inputs_arr.getMatVector(inputs);
        outputs_arr.getMatVector(outputs);

        const Mat& boxesBlob  = inputs[0];
        const Mat& scoresBlob = inputs[1];

        const int B = boxesBlob.size[0];
        const int N = boxesBlob.size[1];
        const int C = scoresBlob.size[1];

        int maxOut = (int)readScalarAs<long long>((inputs.size() >= 3 ? inputs[2] : Mat()), (long long)defaultMaxOut);
        float iouThr = readScalarAs<float>((inputs.size() >= 4 ? inputs[3] : Mat()), defaultIouThr);
        float scoreThr = readScalarAs<float>((inputs.size() >= 5 ? inputs[4] : Mat()), defaultScoreThr);

        const int tasks = B * C;
        std::vector<std::vector<Vec<long long,3>>> tripletsPerBC(tasks);

        cv::parallel_for_(cv::Range(0, tasks), [&](const cv::Range& r){
            for (int taskIdx = r.start; taskIdx < r.end; ++taskIdx) {
                const int b = taskIdx / C;
                const int c = taskIdx % C;

                std::vector<Rect2f> rects;
                std::vector<float> scores;
                std::vector<int> globalIndices;
                rects.reserve(N); scores.reserve(N); globalIndices.reserve(N);

                const float* sPtr = scoresBlob.ptr<float>(b, c);
                for (int n = 0; n < N; ++n) {
                    float sc = sPtr[n];
                    const float* bx = boxesBlob.ptr<float>(b, n);
                    Rect2f r;
                    if (centerPointBox == 0) {
                        const float y1 = bx[0], x1 = bx[1], y2 = bx[2], x2 = bx[3];
                        const float x = std::min(x1, x2), y = std::min(y1, y2);
                        const float w = std::max(0.f, std::abs(x2 - x1));
                        const float h = std::max(0.f, std::abs(y2 - y1));
                        r = Rect2f(x, y, w, h);

Review comment (suggestion):
Just cast to a desired type like this:
```cpp
inputs[4].convertTo(Mat(1, 1, CV_32F, &scoreThr), CV_32F);
```

Code after:
            }
            if (uinputs.size() >= 4 && !uinputs[3].empty()) {
                Mat tmp = uinputs[3].getMat(ACCESS_READ);
                CV_Assert(tmp.channels() == 1 && tmp.total() == 1);
                iouThr = tensorToScalar<float>(tmp);
            }
            if (uinputs.size() >= 5 && !uinputs[4].empty()) {
                Mat tmp = uinputs[4].getMat(ACCESS_READ);
                CV_Assert(tmp.channels() == 1 && tmp.total() == 1);
                scoreThr = tensorToScalar<float>(tmp);
            }
        } else {
            inputs_arr.getMatVector(inputs);
            CV_Assert(inputs.size() >= 2);
            boxesBlob  = inputs[0];
            scoresBlob = inputs[1];
            if (inputs.size() >= 3 && !inputs[2].empty()) {
                CV_Assert(inputs[2].channels() == 1 && inputs[2].total() == 1);
                maxOut = tensorToScalar<int>(inputs[2]);
            }
            if (inputs.size() >= 4 && !inputs[3].empty()) {
                CV_Assert(inputs[3].channels() == 1 && inputs[3].total() == 1);
                iouThr = tensorToScalar<float>(inputs[3]);
            }
            if (inputs.size() >= 5 && !inputs[4].empty()) {
                CV_Assert(inputs[4].channels() == 1 && inputs[4].total() == 1);
                scoreThr = tensorToScalar<float>(inputs[4]);
            }
        }

        const int B = boxesBlob.size[0];
        const int C = scoresBlob.size[1];
        const int tasks = B * C;

        std::vector<std::vector<Vec<int64_t,3>>> tripletsPerBC;
        run(boxesBlob, scoresBlob, maxOut, iouThr, scoreThr, tripletsPerBC);

        int K = 0;
        for (int t = 0; t < tasks; ++t) K += (int)tripletsPerBC[t].size();

        Mat outMat;
        auto outKind = outputs_arr.kind();
        if (outKind == _InputArray::STD_VECTOR_MAT) {
            std::vector<Mat>& outs = outputs_arr.getMatVecRef();
            CV_Assert(outs.size() == 1);
            outs[0].create(K, 3, CV_64S);
            outMat = outs[0];
        } else if (outKind == _InputArray::STD_VECTOR_UMAT) {
            std::vector<UMat> uouts;
            outputs_arr.getUMatVector(uouts);
            CV_Assert(uouts.size() == 1);