Quantcast
Viewing all articles
Browse latest Browse all 6129

cvSaveImage compilation error on C OpenCV 3.4.20

Hello I try to get into OpenCV for my project. I download the version 3.4.20 that includes the deprecated C headers because my code is on C.

 #include<stdio.h> #include "opencv/opencv/include/opencv/cv.h" #include "opencv/opencv/include/opencv/highgui.h" #include "opencv/opencv/include/opencv/cxcore.h"void convertToGray(const char* inputImagePath, const char* outputImagePath) {IplImage* inputImage = cvLoadImage(inputImagePath, 3);if (!inputImage) {    printf("Error: Unable to load input image.\n");    return;}if (!cvSaveImage(outputImagePath, inputImage)) {    printf("Error: Unable to save output image.\n");}cvReleaseImage(&inputImage);}int main() {   convertToGray("baboon.jpg", "baboon_grey.jpg");   return 0; }

I just want to copy an input image into another. I use cmake file:

     cmake_minimum_required(VERSION 2.8)     project( jpg )     find_package( OpenCV REQUIRED )     add_executable( jpg jpg.c )     target_link_libraries( jpg ${OpenCV_LIBS} )

When try to compile this error throws:

user@walldm48:~/Desktop/Projet_Diplome$ makeConsolidate compiler generated dependencies of target jpg[ 50%] Building C object CMakeFiles/jpg.dir/jpg.c.o/home/user/Desktop/Projet_Diplome/jpg.c: In function ‘convertToGray’:/home/user/Desktop/Projet_Diplome/jpg.c:9:28: warning: implicit declaration of function ‘cvLoadImage’; did you mean ‘cvCloneImage’? [-Wimplicit-function-declaration]    9 |     IplImage* inputImage = cvLoadImage(inputImagePath, 3);      |                            ^~~~~~~~~~~      |                            cvCloneImage/home/user/Desktop/Projet_Diplome/jpg.c:9:28: warning: initialization of ‘IplImage *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]/home/user/Desktop/Projet_Diplome/jpg.c:19:10: warning: implicit declaration of function ‘cvSaveImage’; did you mean ‘cvShowImage’? [-Wimplicit-function-declaration]   19 |     if (!cvSaveImage(outputImagePath, inputImage)) {      |          ^~~~~~~~~~~      |          cvShowImage[100%] Linking C executable jpg/usr/bin/ld: CMakeFiles/jpg.dir/jpg.c.o: in function `convertToGray':jpg.c:(.text+0x1514): undefined reference to `cvLoadImage'/usr/bin/ld: jpg.c:(.text+0x154c): undefined reference to `cvSaveImage'collect2: error: ld returned 1 exit statusmake[2]: *** [CMakeFiles/jpg.dir/build.make:112: jpg] Error 1make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/jpg.dir/all] Error 2make: *** [Makefile:91: all] Error 2

Could someone explain what I doing wrong ?

Thanks!


Viewing all articles
Browse latest Browse all 6129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>