2017-08-28 60 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 。