3

最近、私のマシンにOpencvをインストールしました。それはPythonでうまく機能します(私はちょうどいくつかの例えばプログラムによってそれをチェックしました)。しかし、Pythonにはチュートリアルがないため、cに移行することにしました。http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/からHelloworldプログラムを実行します

私のプログラムは

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>


int main(int argc, char *argv[])
{
  IplImage* img = 0; 
  int height,width,step,channels;
  uchar *data;
  int i,j,k;

  if(argc<2){
    printf("Usage: main <image-file-name>\n\7");
    exit(0);
  }

  // load an image  
  img=cvLoadImage(argv[1]);
  if(!img){
    printf("Could not load image file: %s\n",argv[1]);
    exit(0);
  }

  // get the image data
  height    = img->height;
  width     = img->width;
  step      = img->widthStep;
  channels  = img->nChannels;
  data      = (uchar *)img->imageData;
  printf("Processing a %dx%d image with %d channels\n",height,width,channels); 

  // create a window
  cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
  cvMoveWindow("mainWin", 100, 100);

  // invert the image
  for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
    data[i*step+j*channels+k]=255-data[i*step+j*channels+k];

  // show the image
  cvShowImage("mainWin", img );

  // wait for a key
  cvWaitKey(0);

  // release the image
  cvReleaseImage(&img );
  return 0;
}

最初にコンパイル中に次のエラーが発生しました

hello-world.c:4:16: fatal error: cv.h: No such file or directory
compilation terminated.

そして私はこのようにコンパイルすることによってこのエラーを修正します

gcc -I/usr/lib/perl/5.12.4/CORE -o hello-world hello-world.c

しかし今、エラーは

 In file included from hello-world.c:4:0:
/usr/lib/perl/5.12.4/CORE/cv.h:14:5: error: expected specifier-qualifier-list before ‘_XPV_HEAD’
 hello-world.c:5:21: fatal error: highgui.h: No such file or directory
 compilation terminated.

Qns:このヘッダーは私のシステムにインストールされていませんか?このコマンドを使用している間、find / usr -name "highgui.h"何も見つかりませんこのヘッダーがシステムにない場合は、これをインストールしますか?

私を助けてください 。私はopencvの初心者です

4

2 に答える 2

4

まず、マシンに highgui.h が存在するかどうかを確認します。

sudo find /usr/include -name "highgui.h"

パスで見つかった場合は、「/usr/include/opencv/highgui.h」と言ってから、次を使用します。

#include <opencv/highgui.h> in your c file.

また

コンパイル中に追加できます

-I/usr/include/opencv in gcc line 

ただし、cファイルのインクルード行は次のようになります。

#include "highgui.h"

最初のコマンドが失敗した場合は、マシン上で highgui.h が「見つからない」ということです。次に、明らかにいくつかのパッケージがありません。そのパッケージ名を把握するには、apt-find コマンドを使用します。

sudo apt-find search highgui.h

私のマシンでは、次のようになりました。

libhighgui-dev: /usr/include/opencv/highgui.h
libhighgui-dev: /usr/include/opencv/highgui.hpp

apt-find がない場合は、最初に次を使用してインストールします。

sudo apt-get install apt-find 

これで、パッケージ名がわかったので、次を発行します。

sudo apt-get install libhighgui-dev

これが完了したら、find コマンドを使用してヘッダーがインストールされている正確な場所を確認し、それに応じてインクルード パスを変更します。

于 2012-12-28T11:23:30.893 に答える
-1

私のプロジェクトには次のヘッダーがあります。

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/features2d/features2d.hpp>

OpenCV 2.4.2 のバージョン

于 2012-12-28T10:33:22.113 に答える