|
#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";
|
|
|
|
bool runOnGPU = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inference inf(projectBasePath + "/yolov8s.onnx", cv::Size(640, 640), "classes.txt", runOnGPU);
|
|
|
|
std::vector<std::string> imageNames;
|
|
imageNames.push_back(projectBasePath + "/ultralytics/assets/bus.jpg");
|
|
imageNames.push_back(projectBasePath + "/ultralytics/assets/zidane.jpg");
|
|
|
|
for (int i = 0; i < imageNames.size(); ++i)
|
|
{
|
|
cv::Mat frame = cv::imread(imageNames[i]);
|
|
|
|
|
|
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;
|
|
|
|
|
|
cv::rectangle(frame, box, color, 2);
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
|
|
float scale = 0.8;
|
|
cv::resize(frame, frame, cv::Size(frame.cols*scale, frame.rows*scale));
|
|
cv::imshow("Inference", frame);
|
|
|
|
cv::waitKey(-1);
|
|
}
|
|
}
|
|
|