Compilation error cv :: gpu

I am using the main OpenCV branch (3.0.0. Dev) with CUDA on Ubuntu 12.04 and trying to compile the following opencv with gpu code:

#include <iostream> #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; } 

Compilation command:

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

It has the following compilation errors:

 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; ^ 

Is there something wrong with installing OpenCV or changing the API in Opencv 3.0.0?

+6
source share
2 answers

The gpu module has been modified in OpenCV 3.0. It was divided into several modules, it was renamed to cuda and gpu:: the namespace was renamed to cuda:: . The correct code for OpenCV 3.0:

 #include <iostream> #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; } 
+19
source

Ah, they played master with constants. Expect the CV_* prefix to CV_* deleted almost anywhere (except for the CV_8U types, etc. Still alive).

So this is cv::THRESH_BINARY , cv::LOAD_IMAGE_GRAYSCALE , but .... cv::COLOR_BGR2GRAY (you have not used it now, but I will save you from the search;))

Sorry, I have no experience with GPU materials, so I can’t solve the last puzzle.

+6
source

Source: https://habr.com/ru/post/955931/


All Articles