Erreur de compilation cv :: gpu

J’utilise OpenCV master branch (3.0.0. Dev) avec CUDA sur Ubuntu 12.04 et tente de comstackr l’opencv suivant avec le code gpu:

#include  #include "opencv2/opencv.hpp" #include "opencv2/core.hpp" #include "opencv2/highgui.hpp" #include "opencv2/gpu/gpu.hpp" using namespace cv; int main (int argc, char* argv[]) { try { cv::Mat src_host = cv::imread("file.png", CV_LOAD_IMAGE_GRAYSCALE); cv::gpu::GpuMat dst, src; src.upload(src_host); cv::gpu::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY); cv::Mat result_host = dst; cv::imshow("Result", result_host); cv::waitKey(); } catch(const cv::Exception& ex) { std::cout << "Error: " << ex.what() << std::endl; } return 0; } 

La commande de compilation est:

 g++ testgpu.cpp -o test `pkg-config --cflags --libs opencv` -lopencv_gpu 

Il contient les erreurs de compilation suivantes:

 testgpu.cpp: In function 'int main(int, char**)': testgpu.cpp:13:51: error: 'CV_LOAD_IMAGE_GRAYSCALE' was not declared in this scope cv::Mat src_host = cv::imread("file.png", CV_LOAD_IMAGE_GRAYSCALE); ^ testgpu.cpp:17:52: error: 'CV_THRESH_BINARY' was not declared in this scope cv::gpu::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY); ^ testgpu.cpp:19:31: error: conversion from 'cv::gpu::GpuMat' to non-scalar type 'cv::Mat' requested cv::Mat result_host = dst; ^ 

Il y a quelque chose qui cloche avec l’installation d’OpenCV ou le changement d’API dans Opencv 3.0.0?

Le module gpu été repensé dans OpenCV 3.0. Il a été divisé en plusieurs modules, il a été renommé en cuda et gpu:: namespace a été renommé en cuda:: . Le code correct pour OpenCV 3.0:

 #include  #include "opencv2/opencv.hpp" #include "opencv2/core.hpp" #include "opencv2/highgui.hpp" #include "opencv2/cudaarithm.hpp" using namespace cv; int main (int argc, char* argv[]) { try { cv::Mat src_host = cv::imread("file.png", cv::IMREAD_GRAYSCALE); cv::cuda::GpuMat dst, src; src.upload(src_host); cv::cuda::threshold(src, dst, 128.0, 255.0, cv::THRESH_BINARY); cv::Mat result_host(dst); cv::imshow("Result", result_host); cv::waitKey(); } catch(const cv::Exception& ex) { std::cout << "Error: " << ex.what() << std::endl; } return 0; } 

Ah, ils ont joué avec les constantes en maître. Attendez-vous à ce que le préfixe CV_* supprimé presque n’importe où (sauf les types, CV_8U et autres encore en vie).

Donc cv::THRESH_BINARY , cv::LOAD_IMAGE_GRAYSCALE , mais …. cv::COLOR_BGR2GRAY (vous ne l’avez pas utilisé maintenant, mais je vous épargnerai la recherche;))

Désolé, je n’ai aucune expérience en matière de GPU, je ne peux donc pas résoudre la dernière énigme.