安装 opencv eclipse

安装 opencv eclipse

我正在使用 ubuntu 13.10,并尝试在 eclipse 上安装 opencv。我正在遵循本教程关联

我不知道我的图书馆在哪里。这是我在尝试查找文件时得到的结果。

       donbeo@donbeo-HP-EliteBook-Folio-9470m:~$ pkg-config --libs opencv
        -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann 
    -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml 
-lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab  
        donbeo@donbeo-HP-EliteBook-Folio-9470m:~$ 

它不报告文件路径。我尝试了不同的路径,但总是收到编译错误

22:26:06 **** Incremental Build of configuration Debug for project machine_learning ****
make all 
Building target: machine_learning
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "machine_learning"  ./src/prova.o   -lopencv_core  -lopencv_calib3d  -lopencv_objdetect  -lopencv_contrib  -lopencv_legacy  -lopencv_flann -lopencv_imgproc  -lopencv_highgui  -lopencv_ml  -lopencv_video -l\ opencv_features2d
/usr/bin/ld: cannot find -l opencv_features2d
collect2: error: ld returned 1 exit status
make: *** [machine_learning] Error 1

22:26:06 Build Finished (took 114ms)

错误可能出在 lib 路径中。我该如何解决这个问题?

编辑:

安装后我遇到了各种问题。特别是重启和登录后,屏幕变黑了。

正如这篇文章所表达的那样错误 Ubuntu 13.10 黑屏

我已经能够使用此博客中的信息恢复我的系统

http://www.anickle.com/2014/01/19/ubuntu-13-10-intel-graphics-killed-by-opencv/

现在看来它正在部分发挥作用。

我可以运行这个示例代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ml/ml.hpp>

using namespace cv;

int main()
{
    // Data for visual representation
    int width = 512, height = 512;
    Mat image = Mat::zeros(height, width, CV_8UC3);

    // Set up training data
    float labels[4] = {1.0, -1.0, -1.0, -1.0};
    Mat labelsMat(4, 1, CV_32FC1, labels);

    float trainingData[4][2] = { {501, 10}, {255, 10}, {501, 255}, {10, 501} };
    Mat trainingDataMat(4, 2, CV_32FC1, trainingData);

    // Set up SVM's parameters
    CvSVMParams params;
    params.svm_type    = CvSVM::C_SVC;
    params.kernel_type = CvSVM::LINEAR;
    params.term_crit   = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);

    // Train the SVM
    CvSVM SVM;
    SVM.train(trainingDataMat, labelsMat, Mat(), Mat(), params);

    Vec3b green(0,255,0), blue (255,0,0);
    // Show the decision regions given by the SVM
    for (int i = 0; i < image.rows; ++i)
        for (int j = 0; j < image.cols; ++j)
        {
            Mat sampleMat = (Mat_<float>(1,2) << j,i);
            float response = SVM.predict(sampleMat);

            if (response == 1)
                image.at<Vec3b>(i,j)  = green;
            else if (response == -1)
                 image.at<Vec3b>(i,j)  = blue;
        }

    // Show the training data
    int thickness = -1;
    int lineType = 8;
    circle( image, Point(501,  10), 5, Scalar(  0,   0,   0), thickness, lineType);
    circle( image, Point(255,  10), 5, Scalar(255, 255, 255), thickness, lineType);
    circle( image, Point(501, 255), 5, Scalar(255, 255, 255), thickness, lineType);
    circle( image, Point( 10, 501), 5, Scalar(255, 255, 255), thickness, lineType);

    // Show support vectors
    thickness = 2;
    lineType  = 8;
    int c     = SVM.get_support_vector_count();

    for (int i = 0; i < c; ++i)
    {
        const float* v = SVM.get_support_vector(i);
        circle( image,  Point( (int) v[0], (int) v[1]),   6,  Scalar(128, 128, 128), thickness, lineType);
    }

    imwrite("result.png", image);        // save the image

    imshow("SVM Simple Example", image); // show it to the user
    waitKey(0);

}

但是当我尝试运行时收到错误

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

using namespace cv;

int main( int argc, char** argv )
{
  Mat image;
  image = imread( argv[1], 1 );

  if( argc != 2 || !image.data )
    {
      printf( "No image data \n" );
      return -1;
    }

  namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
  imshow( "Display Image", image );

  waitKey(0);

  return 0;
}

Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/prova.d" -MT"src/prova.d" -o "src/prova.o" "../src/prova.cpp"
../src/prova.cpp:1:16: fatal error: cv.h: No such file or directory
 #include <cv.h>

答案1

由于同一命令中的所有前面的库似乎都已成功找到,因此我认为库路径没有问题 - 更可能的是您的问题是您的命令行中有一个不合适的反斜杠

... -lopencv_video -l\ opencv_features2d ...

如果你将其更改为

... -lopencv_video -lopencv_features2d ...


它还应该与后面的空格一起使用-l

... -lopencv_video -l opencv_features2d ...

尽管手册页不推荐这样做:

   -llibrary
   -l library
       Search the library named library when linking.  (The second
       alternative with the library as a separate argument is only for
       POSIX compliance and is not recommended.)


据我所知,反斜杠在这种情况下才是合法的行继续符IE

... -lopencv_video -l\
opencv_features2d ...

-l(带有换行符)我认为也可以,尽管在我看来在之前中断会更自然。

相关内容