Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
Description
System Information
OpenCV Version: 4.10.0
Operating System / Platform: Ubuntu 20.04 (Jetson with Jetpack 5.1.1)
Compiler & compiler version: GCC 9.4.0
Detailed description
I am using OpenCV 4.10.0 for my project to run YOLOv9, as it is the only version with which I have been able to execute YOLOv9 correctly. The problem arises when I use cv::cvtColor in conjunction with YOLOv9 and other OpenCV functions. Specifically, if I uncomment the line:
cv::cvtColor(FrameRGBc0, framec0_gray, cv::COLOR_RGB2GRAY);
the program compiles successfully without any errors using the command:
g++ -O3 test_cpp_example.cpp -o test_cpp_example `pkg-config --cflags --libs opencv4` -lpthread
However, when I run the program, I encounter the following runtime error:
sudo ./test_cpp_example./test_cpp_example: symbol lookup error: ./test_cpp_example: undefined symbol: _ZN2cv8cvtColorERKNS_11_InputArrayERKNS_12_OutputArrayEiiIf I comment out the cv::cvtColor line, the program runs without any issues and produces the expected output:
sudo ./test_cpp_exampleOpenCV version : 4.10.0Major version : 4Minor version : 10Subminor version : 0rows is:8400dim is:84rows is:8400dim is:84rows is:8400dim is:84rows is:8400I have also tried downgrading to OpenCV 4.9.0. While it resolves the cvtColor issue, YOLOv9 does not return bounding boxes correctly in that version, which is why I need to use OpenCV 4.10.0.
Additional Information
Platform: Jetson Orin NanoOpenCV Version: 4.10.0 (installed manually and also using (https://github.com/mdegans/nano_build_opencv/tree/master))YOLOv9 Integration: Works correctly with other OpenCV functions.Behavior with OpenCV 4.9.0: cv::cvtColor runs without issue, but YOLOv9 does not work correctly.Expected Behavior
The program should run without any runtime errors when using cv::cvtColor in OpenCV 4.10.0.
Actual Behavior
The program throws a runtime error related to cv::cvtColor, even though the compilation is successful.
Request for Assistance
Could you please help identify what might be causing this runtime issue? I have confirmed that the rest of the program behaves as expected, and this problem only occurs when cv::cvtColor is used in OpenCV 4.10.0.
Log of last installation of 4.10.0:
Code
#include <iostream>#include <opencv2/core/core.hpp>#include <opencv2/imgproc.hpp>#include <opencv2/highgui.hpp>#include <opencv2/dnn.hpp>#include <float.h>#include <stdio.h>#include <vector>#include <opencv2/opencv.hpp>using namespace cv;using namespace std;using namespace dnn;std::vector<std::string> class_names{"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard", "tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "couch", "potted plant", "bed", "dining table", "toilet", "tv", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear", "hair drier", "toothbrush"};void porcess_with_one_image(cv::dnn::Net &net,cv::Mat& frame,float modelinput_height, float modelinput_width){ float modelScoreThreshold=0.2; float modelNMSThreshold=0.3; //image preprocess int w = frame.cols; int h = frame.rows; int _max = std::max(h, w); cv::Mat image = cv::Mat::zeros(cv::Size(_max, _max), CV_8UC3); cv::Rect roi(0, 0, w, h); frame.copyTo(image(roi)); float x_factor = image.cols / modelinput_width; float y_factor = image.rows / modelinput_height; // inference using model cv::Mat blob; cv::dnn::blobFromImage(image,blob,1 / 255.0, cv::Size(modelinput_height, modelinput_width), cv::Scalar(), true, false); net.setInput(blob); std::vector<cv::Mat> outputs; net.forward(outputs, net.getUnconnectedOutLayersNames()); // postprocess the image // yolov8 has an output of shape (batchSize, 84, 8400) ( box[x,y,w,h]+Num classes ) int rows = outputs[0].size[2]; //8400 int dimensions =outputs[0].size[1]; //84 std::cout<<"rows is:"<<rows<<std::endl; std::cout<<"dim is:"<<dimensions<<std::endl; //(1,84,8400)-->(84,8400) outputs[0] = outputs[0].reshape(1, dimensions); //(84,8400) --> (8400,84) cv::transpose(outputs[0], outputs[0]); //get the first data pointer;finaaly will get all 8400 bounding box float *data = (float *)outputs[0].data; // the storage to save the results std::vector<int> class_ids; std::vector<float> confidences; std::vector<cv::Rect> boxes; //rows stand for the total number of bounding box for (int i = 0; i < rows; ++i) { //skip the x,y,w,h float *classes_scores = data+4; cv::Mat scores(1, class_names.size(), CV_32FC1, classes_scores); cv::Point class_id; double maxClassScore; minMaxLoc(scores, 0, &maxClassScore, 0, &class_id); if (maxClassScore > modelScoreThreshold) { confidences.push_back(maxClassScore); class_ids.push_back(class_id.x); float x = data[0]; float y = data[1]; float w = data[2]; float h = data[3]; int left = int((x - 0.5 * w) * x_factor); int top = int((y - 0.5 * h) * y_factor); int width = int(w * x_factor); int height = int(h * y_factor); boxes.push_back(cv::Rect(left, top, width, height)); } //pointer to next 84 group data += dimensions; } // NMS std::vector<int> indexes; cv::dnn::NMSBoxes(boxes, confidences, modelScoreThreshold, modelNMSThreshold, indexes); for (size_t i = 0; i < indexes.size(); i++) { int index = indexes[i]; int idx = class_ids[index]; cv::rectangle(frame, boxes[index], (0,0,255), 2, 8); cv::rectangle(frame, cv::Point(boxes[index].tl().x, boxes[index].tl().y - 20), cv::Point(boxes[index].br().x, boxes[index].tl().y), cv::Scalar(255, 255, 255), -1); cv::putText(frame, class_names[idx], cv::Point(boxes[index].tl().x, boxes[index].tl().y - 10), cv::FONT_HERSHEY_SIMPLEX, .5, cv::Scalar(0, 0, 0)); }}// void detect_video(std::string& onnxpath,float modelinput_height, float modelinput_width,std::string video_name)void detect_video(cv::dnn::Net &net,float modelinput_height, float modelinput_width,std::string video_name){ cv::VideoCapture capture(video_name); cv::Mat frame; while (true) { bool ret = capture.read(frame); if (frame.empty()) { break; } int64 start = cv::getTickCount(); porcess_with_one_image(net,frame,modelinput_height, modelinput_width); float t = (cv::getTickCount() - start) / static_cast<float>(cv::getTickFrequency()); putText(frame, cv::format("FPS: %.2f", 1.0 / t), cv::Point(20, 40), cv::FONT_HERSHEY_PLAIN, 2.0, cv::Scalar(255, 0, 0), 2, 8); cv::imshow("OpenCV4.10 inference FOR YOLOV9", frame); char c = cv::waitKey(1); if (c == 27) { break; } }}int main(){ std::cout << "OpenCV version : " << CV_VERSION << std::endl; std::cout << "Major version : " << CV_MAJOR_VERSION << std::endl; std::cout << "Minor version : " << CV_MINOR_VERSION << std::endl; std::cout << "Subminor version : " << CV_SUBMINOR_VERSION << std::endl; std::string onnxpath = "yolov9s_simplified.onnx"; auto net = cv::dnn::readNetFromONNX(onnxpath); net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA); net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA); cv::Mat FrameRGBc0; string name_frame_c0 = "frame_60_c0.jpg"; FrameRGBc0 = cv::imread(name_frame_c0, cv::IMREAD_COLOR); //Convert to gray scale: cv::Mat framec0_gray; // cv::cvtColor(FrameRGBc0, framec0_gray, cv::COLOR_RGB2GRAY); // cv::imshow("OpenCV4.10 inference FOR YOLOV9", framec1_gray); // char c = cv::waitKey(0); detect_video(net,640.0,640.0,"40030-424911975_tiny.mp4"); return 0;}Steps to reproduce
I will attach the source code and onnx.
Steps to Reproduce
1 - Compile the code with the line cv::cvtColor(FrameRGBc0, framec0_gray, cv::COLOR_RGB2GRAY); uncommented using the command:
g++ -O3 test_cpp_example.cpp -o test_cpp_example `pkg-config --cflags --libs opencv4` -lpthread
2 - Run the executable:
sudo ./test_cpp_example
3 - Observe the runtime error.
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)