I’m encountering issues while compiling and running my OpenCV project with CUDA in Visual Studio. I’m using Visual Studio 2022 in windows 11 and have configured OpenCV 4.8.0 with CUDA 12.1 and CUDNN 8.9.3 . Despite following the setup instructions, I’m receiving an error during compilation/execution. The error message I’m encountering is Unhandled exception at 0x00007FFD4697DF51 (cudnn64_8.dll) in TestTensorflow.exe: Fatal program exit requested
., and it occurs at outputs = net.forward()
;. I’ve verified my CUDA installation and ensured that the necessary environment variables and paths are correctly set up. Any insights or suggestions on how to resolve this issue would be greatly appreciated
#include <opencv2/core.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <fstream>
#include <iostream>
#include <opencv2/core/utils/logger.hpp>
#include<opencv2/opencv.hpp>
#include<opencv2/dnn.hpp>
#include<opencv2/dnn/all_layers.hpp>
using namespace std;
using namespace cv;
using namespace dnn;
const float INPUT_WIDTH = 640.0;
const float INPUT_HEIGHT = 640.0;
std::vector<std::string> load_class_list()
{
vector<string> class_names;
ifstream ifs(string("namesPpe.txt").c_str());
string line;
while (getline(ifs, line))
{
cout<<line <<endl;
class_names.push_back(line);
}
return class_names;
// Load in all the classes from the file
}
cv::dnn::Net load_net() {
auto net = cv::dnn::readNetFromONNX("yolov8x.onnx");
if (cv::cuda::getCudaEnabledDeviceCount()) {
cout << "cuda esta disponible";
net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA);
//net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
}
else {
cout << "cuda NO esta disponible";
}
return net;
}
//************************************************************************************************************************
Mat pre_process(Mat& input_image, Net& net)
{
//Convert to blob.
Mat blob = blobFromImage(input_image, 1.0, Size(INPUT_WIDTH, INPUT_HEIGHT), Scalar(104.0, 117.0, 123.0), true, false);;
net.setInput(blob);
Mat outputs;
outputs = net.forward();
return outputs;
}
int main() {
//imprimimos y mostramos las classes
std::vector<string> class_names = load_class_list();
cv::dnn::Net net = load_net();
cv::Mat input_image = cv::imread("image.jpg");
cv::Mat outputs = pre_process(input_image, net);
return 0;
}
Ronald Zepita Iquize is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.