根据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->宽度时,它会导致崩溃,在编译上面的代码时会发出警告。
/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");
我不眠之夜想弄清楚,谷歌帮不了忙,是OpenCV版本还是C版本?,我使用的是Opencv2 3.3.0,请随时询问是否需要任何信息
发布于 2017-08-28 05:37:10
第一段代码没有什么问题,如果用g++而不是gcc编译,应该运行得很好。
您正在隐式地将第二段代码从IplImage*
转换为int
,这是错误的,不会运行。
有关cvRound()
函数的警告和错误与OpenCV C有关,它已经有一段时间没有更新了,很可能会在将来的版本中删除。大多数新的OpenCV功能只存在于C++ API中。
在have中提到与cvRound()
函数有关的错误的其他帖子:
https://github.com/opencv/opencv/issues/6076
https://github.com/opencv/opencv/issues/8438
https://github.com/opencv/opencv/issues/8658
在未来,尝试使用OpenCV C++ API以获得最佳的结果。
https://stackoverflow.com/questions/45916209
复制相似问题