OpenCV 245首次出现错误

Ork*_*glu 6 opencv

我下载了opencv-2.4.5的源代码,我按照教程(在windows的opencv网站上)关于安装我自己的库的一切.好.我用cmake创建了opencv.sln文件,然后我用visual studio 2010专业人员打开它,然后点击构建解决方案,但只有9个成功.大多数200失败,大多数关于tbbd.lib的错误未找到,并且在LNK1104错误时找不到opencv_core245d.lib.我试图解决它多少天.我试图展示文件的方式......任何人都可以帮忙吗?这是关于我的论文.(没有公共语言支持的构建)

Jos*_*ers 7

坍方

I spent a good 15 hours or so to get the homework finished using OpenCV. 14.5 of those hours were spent just getting it setup properly. I ran through about 7 tutorial videos, several set up guides, and read hundreds of posts containing resolutions to the same erros I was getting.So I understand that simply installing OpenCV is not a trivial task and there are several steps to do this. So here is a straightforward tutorial for setting it up if you want to use openCV.

It is important to understand how things work as far as linking goes. There are three types of files, your headers that you include, the .dlls that contain the functions, and the libraries that contain instructions for how to call the functions in the .dlls. So here, rather than add just the .dlls as dependencies in the input linker, we are going to add the lib files. We will then create a System Environment variable that will tell the machine where to look for the .dll files when their corresponding library files are referenced. We will be creating a Property Sheet so that when we create a new project, we can simply add the settings to our project by clicking "Add Existing Property Sheet" instead of adding a new one. This way, we never have to go through this again.

FOLLOW THESE STEPS EXACTLY AND MAKE SURE VISUAL STUDIO IS CLOSED BEFORE CONTINUING

NOTE: When text is given in quotes with instructions to copy said text, do not include the quotes.

  • First of all, the easy part - download OpenCV 2.4.5 from their website. http://opencv.org/ and click OpenCV for Windows. It will download OpenCV 2.4.5.exe.

Install OpenCV

  • When the download finishes, double click OpenCV-2.4.5.exe to run it.

  • When asked where to extract the files, type ino the text box: "C:\"

  • C:\opencv should have been created upon completion. Navigate there to make sure.

Setup Environment Variables

  • WINDOWS 8 USERS:

     - Right click the bottom left corner of your screen when the start icon pops up.
    
     - Click "Command Prompt (Admin)"
    
     - Type "SETX -m OPENCV_DIR C:\opencv\build" and press enter to set the opencv build directory as a System Environment Variable. Wait for the console to give you confirmation that it is set.
    
     - Right click the bottom left corner of your screen when the "Start" icon pops up. Click  System -> Advanced System Settings -> Environment Variables
    
     - In the "System Variables" list box, under the "Variable" collumn, find "Path".
    
     - Highlight the "Path" row and click edit.
    
     - Click in the "Variable Value" text box and hit the "end" key on your keyboard to scroll to the end of the line and add a semicolon.
    
     - Type the following: "C:\opencv\build\x86\vc10\bin;C:\opencv\build\x86\vc10" and click "OK". This will add the openCV bin directory to the system path.
    
    Run Code Online (Sandbox Code Playgroud)
  • WINDOWS 7 USERS:

    Follow the same steps. The only difference is how you get to the command prompt and the system settings. Google how to set up an environment variable on Windows 7 if needed.

Setup Visial Studio

NOTE: I highly recommend VS2012 Professional because of advanced syntax highlighting that makes life so much easier when programming C++. This version can be downloaded and installed for free from DreamSpark. Just make and account with your student ID. However, the steps for VS2010 and VS2012 are the same.

  • Open Visual Studio

    • Click "New Project" and under "C++" select "Win32 Console Application".
  • When the window opens click "Next", check "Empty Project", and click "Finish". It is very important that you start with an EMPTY PROJECT without a precompiled header.

  • Locate the "Property Manager." By default, it should be a tab that is sometimes hard to miss. Alternatively it can be accessed by clicking from the toolbar "View" -> "Property Manager".

  • Right Click "Debug | Win32" and select "Add New Project Property Sheet". Name it "OpenCVProps" and click "Add".

  • Right Click your new property sheet and select "Properties".

  • From the left column, go to "C/C++" -> "General" and in the listbox on the right, select "Additional Include Directories" and click "Edit".

  • Add the following THREE directories:

    • "$(OPENCV_DIR)\include"

    • "$(OPENCV_DIR)\include\opencv"

    • "$(OPENCV_DIR)\include\opencv2"

  • From the left column, go to "Linker" -> "General" and in the listbox on the right, select "Additional Library Directories" and click "Edit".

  • Add the following directory:

    • "$(OPENCV_DIR)\x86\vc10\lib"
  • From the left column, go to "Linker" -> "Input" and in the listbox on the right, select "Additional Dependenies" and click "Edit".

  • Add the following .lib files to the depedencies. You may do this by copying and pasting these into that edit box. I have purposely not included a bulletpoint to make it easy for you to copy paste these.

    opencv_core245d.lib opencv_imgproc245d.lib opencv_highgui245d.lib opencv_ml245d.lib opencv_video245d.lib opencv_features2d245d.lib opencv_calib3d245d.lib opencv_objdetect245d.lib opencv_contrib245d.lib opencv_legacy245d.lib opencv_flann245d.lib

NOTE: If building for release, these steps are the same. However, when copying and pasting these files, remove the 'd' from the end of each of them. The 'd' denotes that it is a release library and links to a release .dll.

  • Congrats! The difficult part is almost done! Click "OK" to close the Window.

Creating and Building a Test Project

  • Head over to our Solution Explorer. This can be focused from the toolbar via "View" -> "Solution Explorer"

  • Right click "Source Files" and select "Add" -> "New Item".

  • Select "C++ File (.cpp)" and name the file "main.cpp". Click "Add".

  • Copy and paste the following program and press "F7" on your keyboard and watch the bottom left corner of your screen to see if you get a "Build Succeeded" message. If so, only one step left before you compile and run! If not, please retrace your steps, or comment below and maybe I can help.

    #include <opencv\cv.h>
    #include <opencv\highgui.h>

    int main(int argc, char* argv) 
    {  // openCV .image object
        cv::Mat inputImage;

        //Create a Window
        cv::namedWindow("window",1);

        // Initialize our image.
        inputImage = cv::imread("Lenna.png");

        // Always check to make sure that image has data.
        if(inputImage.empty())
        {
            std::cout << "Image Failed to Load.";
            return -1;
        }
        else
        {
            // All is well, display me.
            cv::imshow("window",inputImage);

            // Wait for user to press a key to exit.
            cvWaitKey(0);
        }

        return 0; 
    } 
  • If the build succeeded, then all that is left is to add the image to your folder. The placement is very important. I have copied the directoy that I have placed mine in. Follow the same directory pattern.

    • "C:\Users\Josh\Documents\Visual Studio 2012\Projects\ConsoleApplication3\ConsoleApplication3\Lenna.png"
  • Now hit "Ctrl + F5" To build, compile, and run to observe your image in the window!!

*IF YOU HAVE A WEBCAM*

  • Copy and paste the following code to check if OpenCV is working without being required to add an image. This is useful because if the above code doesn't work, but this code does, then you know you put the image in the wrong folder.
    #include 
    #include 

    int main(int argc, char* argv) 
    {  // openCV .image object
        cv::Mat image;

        //Create a Window
        cv::namedWindow("window",1);

        // Create the capture object.
        cv::VideoCapture device;

        // Open your webcam.
        device.open(0);

        while (1)
        {
            // Read data from your device and store it to the image frame.
            device >> image;

            // Always check to make sure that image has data.
            if(image.empty())
            {
                std::cout<< "Image Failed to Load.";
                return -1;
            }
            else
            {
                // All is well, display me.
                cv::imshow("window",image);

                // Wait for user to press a key to exit.
                cvWaitKey(33);
            }
        }

        return 0; 
    } 

Happy Coding!! Let me know if something didn't work so I can fix it!


Dra*_*ciu 6

快速回答

我已经设法使用这里的教程编译OpenCV和TBB支持.

规格:Vis​​ual Studio 2012/Win 7(64位)/ OpenCV 2.4.5/CUDA 5

我已下载最新的TBB zip并将其解压缩到C:/ src/OpenCV/dep(如上面链接的教程中所述).

您必须在CMake中使用以下TBB设置(根据您的文件路径进行调整):

TBB_LIB_DIR       ::  C:/src/OpenCV/dep/tbb41_20130314oss/lib/intel64/vc11
TBB_INCLUDE_DIRS  ::  C:/src/OpenCV/dep/tbb41_20130314oss/include/
TBB_STDDEF_PATH   ::  C:/src/OpenCV/dep/tbb41_20130314oss/include/tbb/tbb_stddef.h
WITH_TBB          ::  checked
BUILD_TBB         ::  unchecked
Run Code Online (Sandbox Code Playgroud)

更多信息

最初,我还想安装支持CUDA 5的OpenCV,但似乎CUDA 5与VS2012不兼容.这是我在编译OpenCV时遇到的错误:

Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/Debug/cuda_compile_generated_matrix_operations.cu.obj
nvcc : fatal error : nvcc cannot find a supported cl version. Only MSVC 9.0 and MSVC 10.0 are supported
Run Code Online (Sandbox Code Playgroud)

好消息是你正在使用VS2010,它可以与CUDA一起使用,如此处所示.VS2012可以设置为使用CUDA创建项目,但目前没有办法(AFAIK)编译OpenCV并支持VS2012的CUDA(有关详细信息,请阅读内容).

总之,需要CUDA支持的人应该使用VS2010编译和使用OpenCV.

此外,在编译OpenCV时,我收到以下错误:

error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm118' or greater
fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
Run Code Online (Sandbox Code Playgroud)

我使用这里的说明最终编译OpenCV.我创建了一个属性表,它/Zm130Common Properties> C/C++> Command Line中作为附加选项添加到所有生成的OpenCV项目中.

为了您的参考,我还附加了我使用的CMake配置和CMakeCache.txt文件(因为我正在使用VS2012,CUDA被禁用):

希望这有帮助,如果您需要我详细说明任何步骤,请发表评论.