运行简单的opencv cuda程序需要哪个opencv cuda库?

时间:2015-08-05 12:42:50

标签: c++ visual-studio-2010 opencv

我在win7 x64上使用visual studio 2010构建了opencv with cuda支持。为了运行一个简单的opencv cuda程序,我编写了这段代码,并将输出释放的exe文件放在所有lib和dll文件附近的opencv\built\install\x64\vc10\bin

但是当我运行exe文件时会产生错误No CUDA support (The library is compiled without CUDA support)

这是我的代码:

#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <chrono>
#include <ctime>
#include <opencv2/core/cuda.hpp>

using namespace cv;
using namespace cv::cuda;
using namespace std;

string source_image_addr, gray_image_addr="", source_image_name="";

int convert2gray()
{
    Mat image;
    GpuMat d_image, d_gray_image;
    image = imread((char *)source_image_addr.c_str(), IMREAD_COLOR);

    if(image.empty())
    {
        cout<<"Could not open or find the image"<<std::endl;
        return -1;
    }

    CV_Assert(image.depth() != sizeof(unsigned char));
    std::chrono::time_point<chrono::system_clock> start, end;
    start = chrono::system_clock::now();
    d_image.upload(image);
    cuda::cvtColor(d_image, d_gray_image, CV_RGB2GRAY);
    Mat gray_image(d_gray_image);
    end = chrono::system_clock::now();
    chrono::duration<double> elapsed = end - start;
    cout<<"for image["<<image.cols<<"*"<<image.rows<<"] elapsed = "<<elapsed.count()<<endl;

    //namedWindow("Gray Window", WINDOW_AUTOSIZE);
    //imshow("Gray Window", gray_image);
    imwrite((char *)gray_image_addr.c_str(), gray_image);
}

int main(int argc, char** argv)
{
    if(argc >= 2)
    {
        source_image_addr = argv[1];
        source_image_name = source_image_addr.substr(0, source_image_addr.find_last_of("."));

        if(argc >= 3)
            gray_image_addr = argv[2];
        else
            gray_image_addr = source_image_name + "-gray.jpg";

        if(!convert2gray())
            return -1;
    }
    else
    {
        cout<<"Usage: convert2gray ImageAddress [gray_image_addr]"<<endl;
        return -1;
    }

    //waitKey(0);
    return 0;
}

我已将opencv_world300.dll放在同一个文件夹中。

修改 以下是std::cout << cv::getBuildInformation() << std::endl;

的输出
  videoio: Removing WinRT API headers by default

General configuration for OpenCV 3.0.0 =====================================
  Version control:               3.0.0

  Platform:
    Host:                        Windows 6.1 AMD64
    CMake:                       2.8.11.2
    CMake generator:             Visual Studio 11 Win64
    CMake build tool:            C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe
    MSVC:                        1700

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/x86_amd64/cl.exe  (ver 17.0.50727.1)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR /EHa  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /wd4251 /wd4324 /MP8  /MD /O2 /Ob2 /D NDEBUG  /Zi
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR /EHa  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /wd4251 /wd4324 /MP8  /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/x86_amd64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi    /MP8  /MD /O2 /Ob2 /D NDEBUG  /Zi
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi    /MP8  /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1 
    Linker flags (Release):      /machine:x64   /INCREMENTAL:NO  /debug
    Linker flags (Debug):        /machine:x64   /debug /INCREMENTAL 
    Precompiled headers:         YES
    Extra dependencies:
    3rdparty dependencies:       ippicv

  OpenCV modules:
    To be built:                 hal core flann imgproc ml photo video imgcodecs shape videoio highgui objdetect superres ts features2d calib3d stitching videostab world
    Disabled:                    -
    Disabled by dependency:      -
    Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python2 viz

  Windows RT support:            NO

  GUI: 
    QT:                          NO
    Win32 UI:                    YES
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.8)
    JPEG:                        build (ver 90)
    WEBP:                        build (ver 0.3.1)
    PNG:                         build (ver 1.5.12)
    TIFF:                        build (ver 42 - 4.0.2)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)
    GDAL:                        NO

  Video I/O:
    Video for Windows:           YES
    DC1394 1.x:                  NO
    DC1394 2.x:                  NO
    FFMPEG:                      YES (prebuilt binaries)
      codec:                     YES (ver 55.18.102)
      format:                    YES (ver 55.12.100)
      util:                      YES (ver 52.38.100)
      swscale:                   YES (ver 2.3.100)
      resample:                  NO
      gentoo-style:              YES
    OpenNI:                      NO
    OpenNI PrimeSensor Modules:  NO
    OpenNI2:                     NO
    PvAPI:                       NO
    GigEVisionSDK:               NO
    DirectShow:                  YES
    Media Foundation:            NO
    XIMEA:                       NO
    Intel PerC:                  NO

  Other third-party libraries:
    Use IPP:                     8.2.1 [8.2.1]
         at:                     C:/buildslave64/win64_amdocl/master_PackSlave-win64-vc11-shared/opencv/3rdparty/ippicv/unpack/ippicv_win
    Use IPP Async:               NO
    Use Eigen:                   NO
    Use TBB:                     NO
    Use OpenMP:                  NO
    Use GCD                      NO
    Use Concurrency              YES
    Use C=:                      NO
    Use pthreads for parallel for:
                                 NO
    Use Cuda:                    NO
    Use OpenCL:                  YES

  OpenCL:
    Version:                     dynamic
    Include path:                C:/buildslave64/win64_amdocl/master_PackSlave-win64-vc11-shared/opencv/3rdparty/include/opencl/1.2 C:/Program Files (x86)/AMD/clAmdFft/include C:/Program Files (x86)/AMD/clAmdBlas/include
    Use AMDFFT:                  YES
    Use AMDBLAS:                 YES

  Python 2:
    Interpreter:                 c:/python27_x64/python.exe (ver 2.7.5)

  Python 3:
    Interpreter:                 NO

  Python (for build):            c:/python27_x64/python.exe

  Java:
    ant:                         C:/Program Files (x86)/apache-ant/bin/ant.bat (ver 1.9.2)
    JNI:                         C:/Program Files/Java/jdk1.6.0_45/include C:/Program Files/Java/jdk1.6.0_45/include/win32 C:/Program Files/Java/jdk1.6.0_45/include
    Java wrappers:               NO
    Java tests:                  NO

  Matlab:
    mex:                         NO

  Tests and samples:
    Tests:                       NO
    Performance tests:           NO
    C/C++ Examples:              NO

  Install path:                  C:/buildslave64/win64_amdocl/master_PackSlave-win64-vc11-shared/build/install

  cvconfig.h is in:              C:/buildslave64/win64_amdocl/master_PackSlave-win64-vc11-shared/build/opencv_build
-----------------------------------------------------------------


Could not open or find the image

1 个答案:

答案 0 :(得分:2)

OpenCV预编译二进制文件在没有cuda / GPU支持的情况下进行编译(错误消息告诉您的内容也是&gt;&gt; openCV未经cuda支持编译)。

你必须编译自己的OpenCV(使用CMake很容易完成)来获得cuda支持(激活08-05 18:13:33.711 12931-12931/com.example.ido.grades E/CliptrayUtils﹕ hideClipTrayIfNeeded() TextView is focused!! hideClipTray() 08-05 18:13:35.157 343-433/? E/ThermalEngine﹕ [GPU_MON] 0 percent. Current Sampling Time is 1 sec 08-05 18:13:35.612 12931-12931/com.example.ido.grades E/SQLiteLog﹕ (1) near "CREATE_TABLE": syntax error 08-05 18:13:35.614 12931-12931/com.example.ido.grades E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.ido.grades, PID: 12931 java.lang.IllegalStateException: Could not execute method of the activity at android.view.View$1.onClick(View.java:4014) at android.view.View.performClick(View.java:4763) at android.view.View$PerformClick.run(View.java:19821) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5274) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at android.view.View$1.onClick(View.java:4009)             at android.view.View.performClick(View.java:4763)             at android.view.View$PerformClick.run(View.java:19821)             at android.os.Handler.handleCallback(Handler.java:739)             at android.os.Handler.dispatchMessage(Handler.java:95)             at android.os.Looper.loop(Looper.java:135)             at android.app.ActivityThread.main(ActivityThread.java:5274)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java:372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704) Caused by: android.database.sqlite.SQLiteException: near "CREATE_TABLE": syntax error (code 1): , while compiling: CREATE_TABLE add_course(year TEXT,semester TEXT,course TEXT,points TEXT,grade TEXT); at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:894) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:505) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:726) at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1775) at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1706) at com.example.ido.grades.DatabaseOperations.onCreate(DatabaseOperations.java:26) at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251) at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163) at com.example.ido.grades.DatabaseOperations.putInformation(DatabaseOperations.java:36) at com.example.ido.grades.NewCourseActivity.save(NewCourseActivity.java:73)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java:372)             at android.view.View$1.onClick(View.java:4009)             at android.view.View.performClick(View.java:4763)             at android.view.View$PerformClick.run(View.java:19821)             at android.os.Handler.handleCallback(Handler.java:739)             at android.os.Handler.dispatchMessage(Handler.java:95)             at android.os.Looper.loop(Looper.java:135)             at android.app.ActivityThread.main(ActivityThread.java:5274)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java:372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704) 并设置cuda toolkit目录路径)!

看看: http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html#installation-by-making-your-own-libraries-from-the-source-files

您可能还需要照顾不同的cuda平台: http://docs.opencv.org/modules/gpu/doc/introduction.html

使用WITH_CUDA=ON您可以在运行时打印OpenCV构建设置,如果您不确定如何编译库。