0
votes

According to the OpenCV documentation cvLoadImage must return pointer to IplImage, but it looks like it is returning int.

when I run the below program, i get some warnings which is shown below program

#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);
}

Also I am getting segmentation fault when I run the above code, I am guessing since img is a int so its causing crash when I am trying to access img->width, Warnings when above code is compiled

/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");

warning says incompatible converstion from int, so I have change the IplImage to int and it worked fine and it ourputs some negative integer value for 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);
}

I get the below warnings for the above program

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");

I went sleepless to figure out it, google could not help, is it something to do with OpenCV versions or C versions?, I am using Opencv2 3.3.0, please feel free to ask if any information is required

1
You're missing a header file (forward declaration for the function). - Sourav Ghosh
@Sourav Ghosh, might be but don't know which one - murali krish
did you try adding cv.h? - Sourav Ghosh
yes, still getting that implicit declaration warning, i tried way before - murali krish
In version 3.3.0 cvLoadImage is not in highgui module, it's in imgcodecs -- perhaps #include "opencv2/imgcodecs/imgcodecs_c.h"? - Dan Mašek

1 Answers

0
votes

There's nothing wrong with the first code and should run fine if compiled with g++ instead of gcc.

The second code you're implicitly converting from IplImage* to int which is wrong and will not run.

The warning and errors regarding cvRound() function has to do with OpenCV C API which hasn't been updated in a while and will most likely be removed in a future version. Most of the new OpenCV functionalities are only present in the C++ API.

Other posts which have mentioned errors regarding cvRound() function in the C API:

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

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

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

In the future try to use OpenCV C++ API for best possible results.