Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPP yolov8 detection boxes not right position #15

Open
MyraBaba opened this issue Oct 16, 2023 · 6 comments
Open

CPP yolov8 detection boxes not right position #15

MyraBaba opened this issue Oct 16, 2023 · 6 comments

Comments

@MyraBaba
Copy link

Hi,

I try to test with my images but boxes detection position all left corner not datected face what is the problem here:
left green

Best


`#include <iostream>
#include <vector>
#include <getopt.h>

#include <opencv2/opencv.hpp>

#include "inference.h"

using namespace std;
using namespace cv;

int main(int argc, char **argv)
{
    std::string projectBasePath = "/home/user/ultralytics"; // Set your ultralytics base path

    bool runOnGPU = true;

    //
    // Pass in either:
    //
    // "yolov8s.onnx" or "yolov5s.onnx"
    //
    // To run Inference with yolov8/yolov5 (ONNX)
    //

    // Note that in this example the classes are hard-coded and 'classes.txt' is a place holder.
    Inference inf("/data/dProjects/yolov8-face-landmarks-opencv-dnn/weights/yolov8n-face.onnx", cv::Size(640, 480), "classes.txt", runOnGPU);

    std::vector<std::string> imageNames;
    imageNames.push_back( "/home/alp2080/face_detector_3.jpg");
    imageNames.push_back( "/home/alp2080/detector_2.jpg");

    for (int i = 0; i < imageNames.size(); ++i)
    {
        cv::Mat frame = cv::imread(imageNames[i]);

        // Inference starts here...
        std::vector<Detection> output = inf.runInference(frame);

        int detections = output.size();
        std::cout << "Number of detections:" << detections << std::endl;

        for (int i = 0; i < detections; ++i)
        {
            Detection detection = output[i];

            cv::Rect box = detection.box;
            cv::Scalar color = detection.color;

            // Detection box
            cv::rectangle(frame, box, cv::Scalar(0, 255, 0), 3);

            // Detection box text
            std::string classString = detection.className + ' ' + std::to_string(detection.confidence).substr(0, 4);
            cv::Size textSize = cv::getTextSize(classString, cv::FONT_HERSHEY_DUPLEX, 1, 2, 0);
            cv::Rect textBox(box.x, box.y - 40, textSize.width + 10, textSize.height + 20);

            cv::rectangle(frame, textBox, color, cv::FILLED);
            cv::putText(frame, classString, cv::Point(box.x + 5, box.y - 10), cv::FONT_HERSHEY_DUPLEX, 1, cv::Scalar(0, 0, 0), 2, 0);
        }
        // Inference ends here...

        // This is only for preview purposes
        float scale = 0.8;
        cv::resize(frame, frame, cv::Size(frame.cols*scale, frame.rows*scale));
        cv::imshow("Inference", frame);

        cv::waitKey(-1);
    }
}
`
Screen Shot 2023-10-16 at 21 56 51
@MyraBaba
Copy link
Author

@derronqi We are using yolov5face , its detection and landmarks very accurate than the insightface detection but took 20 ms on the Gpu per frame . Slow for us.

We need to utilize 2 rtsp cam and detect faces faster

@Upliner
Copy link

Upliner commented Dec 6, 2023

I have this bug too

@Upliner
Copy link

Upliner commented Dec 6, 2023

OK, now I found out that "export" function in this repository is buggy. Install ultralytics from pip to get onnx file.

@MyraBaba
Copy link
Author

MyraBaba commented Dec 6, 2023

@Upliner did you compare with scrfd / retina and yolov5face ? quality and speed ?

@Upliner
Copy link

Upliner commented Dec 6, 2023

@Upliner did you compare with scrfd / retina and yolov5face ? quality and speed ?

I only compared with https://github.com/derronqi/yolov7-face the quality is better and CPU speed is faster, I haven't checked GPU speed yet, I think I'll build GPU version tomorrow.

@Upliner
Copy link

Upliner commented Dec 6, 2023

@Upliner did you compare with scrfd / retina and yolov5face ? quality and speed ?

I'm using onnxruntime+CUDA on RTX3060 and yolov8n-face model, average inference time is near 9-10ms. Here is 30 time samples in microseconds:
[8338, 13978, 16457, 14625, 8933, 11802, 13985, 6536, 9729, 7278, 7799, 7864, 7995, 7685, 7965, 6473, 16348, 12040, 9911, 6533, 6022, 8061, 6879, 9495, 7139, 6560, 6707, 6536, 7561, 13201]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants