c - 如何在我的 ubuntu 11.10 中用 C 语言安装 opencv 的头文件

标签 c image-processing opencv header

最近我在我的机器上安装了 Opencv。它在 python 中运行良好(我刚刚通过一些程序检查了它)。但是由于缺少 python 教程,我决定转向 c。我刚刚从 http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/ 运行了一个 Hello world 程序

我的程序是

#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.

问: 是我的系统中没有安装这个 header 吗?当我使用这个命令时 find/usr -name "highgui.h"我没有找到任何东西 如果这个 header 不在我的系统中,我要安装这个吗?

请帮帮我。我是 opencv 新手

最佳答案

首先检查你的机器上是否存在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 行应该变成:

#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 命令查看 header 的安装位置,然后相应地更改包含路径

关于c - 如何在我的 ubuntu 11.10 中用 C 语言安装 opencv 的头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14068042/

相关文章:

c - 发送链表到函数

xcode - imwrite 在 OpenCV 中抛出编译错误

iphone - 用于 iPad 的 GPUImage 框架 (GPUImageStillCamera) 实现

image-processing - Keras ImageDataGenerator 如何查看修改图像的参数

python - 比较两个图像与 python 排除阴影

python - 使用 OpenCV 和 Python 获取图像中颜色的百分比

python - 在 python 中使用 opencv 进行 Blob 过滤

c++ - 随机存取与 SSE 对齐的内存

c - 用 write 代替 printf 进行信号处理

c - C 中的指针 - 一维和二维