【发布时间】:2018-02-05 13:24:34
【问题描述】:
根据 OpenCV 文档,cvLoadImage 必须返回指向 IplImage 的指针,但看起来它正在返回 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->width 时它会导致崩溃,编译上面的代码时会出现警告
/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 的转换不兼容,所以我将 IplImage 更改为 int,它工作正常,它为 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");
睡不着想明白了,google也帮不上忙,是OpenCV版本还是C版本的问题?,我用的是Opencv2 3.3.0,请问需要什么资料
【问题讨论】:
-
您缺少一个头文件(函数的前向声明)。
-
@Sourav Ghosh,可能是但不知道是哪一个
-
您是否尝试添加
cv.h? -
是的,仍然收到隐式声明警告,我之前尝试过
-
在 3.3.0 版本中,
cvLoadImage不在highgui模块中,它在 imgcodecs 中 -- 可能是#include "opencv2/imgcodecs/imgcodecs_c.h"?