Untitled
raw download clone
TEXT
views 100
,
size 2333 b
std::vector<cv::Rect>
TrackerInterface::GetDetectionsMini(EcovisionYoloV3 *p, cv::Mat cvimage, cv::Rect detectZone, int imageWidthPixels, int imageHeightPixels,
                                box *boxes, std::string *labels) {
    std::vector<cv::Rect> vt_rects;
    int numObjects = 0;
    cv::Mat crop_image = cvimage(detectZone);

    float dif_x = detectZone.x;
    float dif_y = detectZone.y;

    p->Detect(
            crop_image,
            yolo_thresh,
            yolo_hier_thresh,
            numObjects);
    if (numObjects > 0 && numObjects < 100) // Realistic maximum
    {
        boxes = new box[numObjects];
        labels = new std::string[numObjects];
        if (!boxes) {
            if (p) delete p;
            p = 0;
            return vt_rects;
        }
        if (!labels) {
            if (p) delete p;
            p = 0;
            if (boxes) {
                delete[] boxes;
                boxes = NULL;
            }
            return vt_rects;
        }

        p->GetBoxes(
                boxes,
                labels,
                numObjects
        );

        int objId = 0;
        int leftTopX = 0, leftTopY = 0, rightBotX = 0, rightBotY = 0;
        for (objId = 0; objId < numObjects; objId++) {
            leftTopX = 1 + imageWidthPixels * (boxes[objId].x - boxes[objId].w / 2) + dif_x;
            leftTopY = 1 + imageHeightPixels * (boxes[objId].y - boxes[objId].h / 2);
            rightBotX = 1 + imageWidthPixels * (boxes[objId].x + boxes[objId].w / 2) + dif_x;
            rightBotY = 1 + imageHeightPixels * (boxes[objId].y + boxes[objId].h / 2);
            cv::Rect rect(cvPoint(leftTopX, leftTopY), cvPoint(rightBotX, rightBotY));
            vt_rects.push_back(rect);
//            cv::rectangle(cvimage, rect, CV_RGB(255, 0, 0), 1, 8, 0);
//            if (labels[objId].c_str()) {
//                putText(cvimage, labels[objId].c_str(), cvPoint(leftTopX, leftTopY),
//                        cv::FONT_HERSHEY_COMPLEX_SMALL, 0.8, cvScalar(200, 200, 250), 1, CV_AA);
//            }
        }

        if (boxes) {
            delete[] boxes;
            boxes = NULL;
        }
        if (labels) {
            delete[] labels;
            labels = NULL;
        }

    }

    return vt_rects;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.