Reputation: 1958
I'm trying to compile that code (houghlines.cpp from gpu samples):
#include <cmath>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/gpu/gpu.hpp"
#include <stdlib.h>
#include <stdio.h>
using namespace std;
using namespace cv;
using namespace cv::gpu;
static void help()
{
cout << "This program demonstrates line finding with the Hough transform." << endl;
cout << "Usage:" << endl;
cout << "./gpu-example-houghlines <image_name>, Default is pic1.png\n" << endl;
}
int main(int argc, const char* argv[])
{
const string filename = argc >= 2 ? argv[1] : "~/Images/skorn00.png";
Mat src = imread(filename, IMREAD_GRAYSCALE);
if (src.empty())
{
help();
cout << "can not open " << filename << endl;
return -1;
}
Mat mask;
Canny(src, mask, 100, 200, 3);
Mat dst_cpu;
cvtColor(mask, dst_cpu, CV_GRAY2BGR);
Mat dst_gpu = dst_cpu.clone();
vector<Vec4i> lines_cpu;
{
const int64 start = getTickCount();
HoughLinesP(mask, lines_cpu, 1, CV_PI / 180, 50, 60, 5);
const double timeSec = (getTickCount() - start) / getTickFrequency();
cout << "CPU Time : " << timeSec * 1000 << " ms" << endl;
cout << "CPU Found : " << lines_cpu.size() << endl;
}
for (size_t i = 0; i < lines_cpu.size(); ++i)
{
Vec4i l = lines_cpu[i];
line(dst_cpu, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 0, 255), 3, CV_AA);
}
GpuMat d_src(mask);
GpuMat d_lines;
HoughLinesBuf d_buf;
{
const int64 start = getTickCount();
gpu::HoughLinesP(d_src, d_lines, d_buf, 1.0f, (float) (CV_PI / 180.0f), 50, 5);
const double timeSec = (getTickCount() - start) / getTickFrequency();
cout << "GPU Time : " << timeSec * 1000 << " ms" << endl;
cout << "GPU Found : " << d_lines.cols << endl;
}
vector<Vec4i> lines_gpu;
if (!d_lines.empty())
{
lines_gpu.resize(d_lines.cols);
Mat h_lines(1, d_lines.cols, CV_32SC4, &lines_gpu[0]);
d_lines.download(h_lines);
}
for (size_t i = 0; i < lines_gpu.size(); ++i)
{
Vec4i l = lines_gpu[i];
line(dst_gpu, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 0, 255), 3, CV_AA);
}
imshow("source", src);
imshow("detected lines [CPU]", dst_cpu);
imshow("detected lines [GPU]", dst_gpu);
waitKey();
return 0;
}
But after running i get this message (excution): /workspace/test_opencv/test_opencv/bin/Release/test_opencv: error while loading shared libraries: libopencv_gpu.so.2.4: cannot open shared object file: No such file or directory
Here is the build : -------------- Build: Release in test_gpu (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -O2 -I/usr/local/include -I/usr/local/include/opencv -c /home/thomas/workspace/test_opencv/test_gpu/main.cpp -o obj/Release/main.o g++ -L/usr/local/include -L/usr/local/include/opencv -o bin/Release/test_gpu obj/Release/main.o -s /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so Output size is 14,44 KB Process terminated with status 0 (0 minutes, 1 seconds) 0 errors, 0 warnings (0 minutes, 1 seconds)
The houghines.cpp from cpu samples work well. It seems it comes from libopen_gpu library compilation. CMAKE doesn't return error when i compile opencv WITH_CUDA. What's wrong?
Upvotes: 0
Views: 5887
Reputation: 1958
I found the problem, it is what i have been expected:
I add in the source file:
cv::gpu::printShortCudaDeviceInfo(cv::gpu::getDevice());
And it returned:
OpenCV Error: No GPU support (The library is compiled without CUDA support) in getDevice, file /build/buildd/opencv-2.4.2+dfsg/modules/core/src/gpumat.cpp, line 182
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.4.2+dfsg/modules/core/src/gpumat.cpp:182: error: (-216) The library is compiled without CUDA support in function getDevice
Now I have to compile opencv with cuda (CMAKE). But i have ever done this part...
Upvotes: 0
Reputation: 11934
Seems to be the same issue as here: openCV program compile error "libopencv_core.so.2.4: cannot open shared object file: No such file or directory" in ubuntu 12.04 , configure everything properly and it should run.
Upvotes: 0