2017-08-28 61 views
0

根据OpenCV文档,cvLoadImage必须返回指向IplImage的指针,但看起来它正在返回int。cvLoadImage返回int?

当我运行下面的程序,我得到一些警告,这显示在下面的程序

#include "highgui.h" 
#include <stdio.h> 

int main(int argc, char** argv) 
{ 
    IplImage *img = cvLoadImage ("/path/to/file/face.jpg"); 
    if(img != NULL) 
      printf("%d", img->width); 
} 

而且我得到段错误,当我运行上面的代码,因为IMG我猜是INT所以其造成当我试图访问img->宽度崩溃,警告时上面的代码被编译

/usr/local/Cellar/opencv/3.3.0_3/include/opencv2/core/types_c.h:929:13: warning: 
     implicit declaration of function 'cvRound' is invalid in C99 
     [-Wimplicit-function-declaration] 
    ipt.x = cvRound(point.x); 
      ^
    main.c:7:21: warning: implicit declaration of function 'cvLoadImage' is invalid 
      in C99 [-Wimplicit-function-declaration] 
     IplImage *img = cvLoadImage ("/path/to/file/face.jpg"); 
         ^
    main.c:7:15: warning: incompatible integer to pointer conversion initializing 
      'IplImage *' (aka 'struct _IplImage *') with an expression of type 'int' 
      [-Wint-conversion] 
     IplImage *img = cvLoadImage ("/path/to/file/face.jpg"); 

警告说,从int不相容converstion,所以我必须改变的IplImage为int和它的工作很好,我牛逼ourputs为IMG一些负面的整数值

#include "highgui.h" 
#include <stdio.h> 

int main(int argc, char** argv) 
{ 
    printf("%s\n","hello world"); 
    int img = cvLoadImage ("/path/to/file/face.jpg"); 
    printf("%d", img); 
} 

我得到下面的警告,上述程序

implicit declaration of function 'cvRound' is invalid in C99 
     [-Wimplicit-function-declaration] 
    ipt.x = cvRound(point.x); 
      ^
main.c:7:15: warning: implicit declaration of function 'cvLoadImage' is invalid 
     in C99 [-Wimplicit-function-declaration] 
    int img = cvLoadImage ("/path/to/file/face.jpg"); 

我去眠弄清楚它,谷歌不能帮助,是它的东西做OpenCV版本或C版本?我使用Opencv2 3.3.0,请随时询问是否需要任何信息

+0

你缺少一个头文件(函数的前向声明)。 –

+0

@Sourav Ghosh,可能是,但不知道你尝试添加'cv.h'的哪一个 –

+0

? –

回答

0

第一个代码没有问题,如果使用g ++而不是gcc编译,应该运行良好。

第二个代码隐含地从IplImage*转换为int这是错误的,不会运行。

关于cvRound()函数的警告和错误与OpenCV C API有关,它在一段时间内未被更新,很可能在将来的版本中被删除。大多数新的OpenCV功能仅存在于C++ API中。

已经提到的错误

其他职位有关cvRound()功能的C API中:

https://github.com/opencv/opencv/issues/6076

https://github.com/opencv/opencv/issues/8438

https://github.com/opencv/opencv/issues/8658

在将来尝试使用尽可能好的结果OpenCV的C++ API 。