Closed Matthew-CQ closed 1 week ago
Hello Matthew-CQ, you are welcome please ensure you use the correct model with the corresponding header.
// Include necessary headers
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include "YOLO11.hpp" // Ensure YOLO11.hpp or other version is in your include path
int main()
{
// Configuration parameters
const std::string labelsPath = "../models/coco.names"; // Path to class labels
const std::string modelPath = "../models/yolo11n.onnx"; // Path to YOLO11 model
const std::string imagePath = "../data/dogs.jpg"; // Path to input image
bool isGPU = true; // Set to false for CPU processing
// Initialize the YOLO11 detector
YOLO11Detector detector(modelPath, labelsPath, isGPU);
// Load an image
cv::Mat image = cv::imread(imagePath);
// Perform object detection to get bboxs
std::vector<Detection> detections = detector.detect(image);
// Draw bounding boxes on the image
detector.drawBoundingBoxMask(image, detections);
// Display the annotated image
cv::imshow("YOLO11 Detections", image);
cv::waitKey(0); // Wait indefinitely until a key is pressed
return 0;
}
Hi Geekgineer,
I am sure that I am using the correct model along with the corresponding header. However, the result is the same as with your code after building.
Hi Matthew,
Please make sure you have built the project according to the README.md also the libs like OpenCV match the current versions etc. for the below image it worked for me.
I have also this problem.
I made sure to have opencv 4.5.5 with this adaptation in the CmakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(yolo_ort)
option(ONNXRUNTIME_DIR "Path to built ONNX Runtime directory." STRING)
message(STATUS "ONNXRUNTIME_DIR: ${ONNXRUNTIME_DIR}")
set(OpenCV_DIR "/home/username/repos/opencv-4.5.5/build")
find_package(OpenCV 4.5.5 REQUIRED)
...
But the output is identical to @Matthew-CQ
In image_interference.cpp
I added this line of code to verify the OpenCV version:
std::cout << "OpenCV Version: " << CV_VERSION << std::endl;
It confirms, that 4.5.5
is used.
Also yolov10 works, but yolov11 does not.
HI, @a333klm
My OpenCV version is 4.5.4. After building OpenCV 4.10.0 and using it, I got the same incorrect results. It's weird. Maybe the ONNX model is incorrect?
Hello guys,
in case you confront issues with the models provided in the project you can get your fresh onnx yolov11 models by exporting the original models or your custom ones using this colab env:
https://colab.research.google.com/github/ultralytics/ultralytics/
regards,
Hi @Geekgineer @a333klm,
I fixed it by using notebook from @Geekgineer to generate a new ONNX model (yolo11n.onnx). After replacing it, I got the correct output.
The steps are shown below:
Run Setup → Predict → Export (change format to ONNX)
Download the yolo11n.onnx model and replace the old one.
Regards,
Hi, Geekgineer,
Thank you for your great work! I encountered an error when using the model (though it works only with yolo10n_uint8.onnx model). Is there something wrong with the decoder part or onnx model? I would appreciate your response at your earliest convenience.
yolo11n.onnx
Other models
Best Regards, Matthew