Eclipse CDTでOpenCVを使う

OpenCVをインストールする(Ubuntu 10.10, Ubuntu 11.10, Ubuntu 12.04OpenCV 2.4をUbuntu 12.04で).

Eclipse CDTをインストールする:

sudo apt-get install eclipse-cdt

Eclipse CDT実行する。ワークスペースを選択。 新しい”C++ Project”作る、名前を書く、”Project type”で”Empty Project”と”Toolchains”で”Linux GCC”選択する.

プロジェクトの右クリックする。”Properties”選択する。”C/C++ Build->Settings”選択する。”Tool Settings”タブに、”GCC C++ Compiler->Includes” “Include paths (-l)” OpenCV include ディレクトリを書く。OpenCVソースコードで”/usr/local/include/opencv2“ですがUbuntuリポジトリのOpenCVで”/usr/include/opencv2“です。

“GCC C++ Linker->Libraries” “Libraries (-l)” OpenCVのこのライブラリ名前を書いてください:

opencv_core
opencv_highgui

“Library search paths (-L)” OpenCV ライブラリのディレクトリを書く。OpenCVソースコードで”/usr/local/lib“ですがUbuntuリポジトリのOpenCVで”/usr/lib“です。

“File->New->Source file” “main.cpp“:

#include "opencv.hpp"

int main(int argc, char* argv[])  {

        IplImage* img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 3 );

        cvCircle( img, cvPoint( 320, 240 ), 100, cvScalar( 255, 0, 0 ), 5 );

        cvNamedWindow( "OpenCV Window", CV_WINDOW_NORMAL );
        cvShowImage( "OpenCV Window", img );

        cvWaitKey(0);

        cvDestroyWindow( "OpenCV Window" );
        cvReleaseImage( &img );

        return 0;
}

“Project->Build Automatically”選択しない. Control+Bか”Project->Build All”.
“Run->Debug Configurations…”, “C/C++ Application”でダブルクリックする。プロジェクトの”Browse…”ボタン選択する。あなたのプロジェクトを選択する。今”Debug”ボタンを選択できる。

Leave a comment ?

5 Comments.

  1. I get two errors by the time I finish evrything and I can’t figure out why.

    Error 1: fatal error: opencv2/photo/photo.hpp: No such file or directory.

    Error 2: make:***[main.o] Error 1

    Any help will be appreciated.

    • You’ll have to give me some more info to help you. How did you configure Eclipse CDT, were do you have your OpenCV installed, what does your code do, etc.

      The first error look if that photo.hpp file is really were you told in the “Include paths (-I) option. There should be a file with that name in “/usr/include/opencv2/photo/photo.hpp” or “/usr/local/include/opencv2/photo/photo.hpp”, those are the usual locations. But I don’t have that “photo” folder in my OpenCV installation…

      The second error is nothing by it self. Look for the real error somewhere before it.

  2. The photo error is what really caught me off course. The folder you are discribing is not in the opencv2 folder (I don’t know why.) All I did to eclipse was add C/C++ on it.

    Also, for the include path, “/usr/local/include/opencv2″ and “/usr/include/opencv2“ didn’t work for me, so I put “/home/programming/OpenCV-2.4.0/include/opencv” instead, which is where the opencv2 folder is located and it worked for me but I’m not sure if that is what is causing the error.

    Thank You.

  3. Hola, Tengo un problema, no me muestra ninguna imagen al ejecutar, pero lo compila sin ningún error. durante el lauching solo muestra esto en la consola
    “Info: Nothing to build for …….” luego al terminar desaparece y no me muestra nada…
    Sabes que puede estar faltando????? Te voy a agradecer la respuesta.

    • Pues diría que lo que pasa es que no estás dándole a ejecutar, sino a compilar una y otra vez. Por eso el mensaje que dice “Nada que construir”, porque ya está compilado. Asegúrate de que estás haciendo click sobre ejecutar y no sobre compilar.

      Espero que te sirva la respuesta.

Leave a Comment