0

我正在尝试编译该代码(来自 gpu 示例的 houghlines.cpp):

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

但运行后我收到此消息(执行):/workspace/test_opencv/test_opencv/bin/Release/test_opencv:加载共享库时出错:libopencv_gpu.so.2.4:无法打开共享对象文件:没有这样的文件或目录

这是构建: -------------- 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/库/libopencv_video。所以 /usr/local/lib/libopencv_videostab.so 输出大小为 14,44 KB 进程以状态 0(0 分 1 秒)终止 0 个错误,0 个警告(0 分 1 秒)

cpu 样本中的 houghines.cpp 运行良好。它似乎来自 libopen_gpu 库编译。当我用 WITH_CUDA 编译 opencv 时,CMAKE 不返回错误。怎么了?

4

2 回答 2

0

似乎与这里的问题相同:openCV 程序编译错误“libopencv_core.so.2.4: cannot open shared object file: No such file or directory” in ubuntu 12.04,正确配置一切,它应该运行。

于 2013-09-02T12:26:02.053 回答
0

我发现了问题,这是我所期望的:我在源文件中添加: cv::gpu::printShortCudaDeviceInfo(cv::gpu::getDevice());

它返回了: 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

现在我必须用 cuda (CMAKE) 编译 opencv。但我曾经做过这部分......

于 2013-09-02T12:53:11.377 回答