cv::imwrite “undefined” when using OpenCV 3.2

asked 2017-04-30 07:39:04 -0500

OtagoHarbour gravatar image

I am using OpenCV 3.2.0 on Ubuntu 64-bit and have the written following code which I call WebImageIO.cpp

 #include <iostream>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "cv.h"
 #include "highgui.h"
 #include <opencv2/core.hpp>
 #include <opencv2/highgui.hpp>
 #include <opencv2/imgproc.hpp>
 #include <opencv2/imgcodecs.hpp>
 #include <opencv2/videoio.hpp>
 #include <math.h>
 #include <windows.h>
 #include "Generic.h"
 #include "Palette.h"
 #include "CWebImageIO.h"

 using namespace cv;


 ERROR_NUMBER CWebImageIO::WriteColourImageToPNGFile(BytePlane bytePlane,  BYTE *bpOutputImage,
         TCHAR *outputFileName)
 {
     int            iNumBands=3;
     int row, col, inputInc, inc;
     BytePlane   bpBufferPlane;

     // Make real colour output plane
     bpBufferPlane=MakeBytePlane(bytePlane.iRows, iNumBands*bytePlane.iColumns, NULL);
     if (!(bpBufferPlane.Data))
         return ERROR_MEMORY_ALLOCATION;

     // Fill buffer plane with test values
     cv::Mat outputImage=cv::Mat(bytePlane.iRows, bytePlane.iColumns, CV_8UC3);
     if (!(outputImage.data))
     {
         FreeBytePlane(bpBufferPlane);
         return ERROR_MEMORY_ALLOCATION;
     }

     memcpy((void *)(outputImage.data), (void *)(bpOutputImage),
             bytePlane.iRows*bytePlane.iColumns*3);

     if (!(imwrite((char *)outputFileName, outputImage)))
     {
         free(bpOutputImage);
         return ErrorWritingFile(outputFileName);
     }

     // Cleanup
     FreeBytePlane(bpBufferPlane);

     return ERROR_NONE;
 }

I then try to build it with the following.

 g++     -o dist/Debug/GNU-Linux/applymodeltoset build/Debug/GNU-Linux/_ext/73c876dd/AffymetrixAnalysis.o build/Debug/GNU-Linux/_ext/73c876dd/AffymetrixIO.o build/Debug/GNU-Linux/_ext/73c876dd/AffymetrixProcessing.o build/Debug/GNU-Linux/_ext/73c876dd/BinaryObject.o build/Debug/GNU-Linux/_ext/73c876dd/BoxFilter.o build/Debug/GNU-Linux/_ext/73c876dd/Branch.o build/Debug/GNU-Linux/_ext/73c876dd/BranchObject.o build/Debug/GNU-Linux/_ext/73c876dd/CWebImageIO.o build/Debug/GNU-Linux/_ext/73c876dd/Consolidation.o build/Debug/GNU-Linux/_ext/73c876dd/Curves.o build/Debug/GNU-Linux/_ext/73c876dd/Distribution.o build/Debug/GNU-Linux/_ext/73c876dd/DraculaLib.o build/Debug/GNU-Linux/_ext/73c876dd/EdgeDetection.o build/Debug/GNU-Linux/_ext/73c876dd/EdgeMatching.o build/Debug/GNU-Linux/_ext/73c876dd/Eigen.o build/Debug/GNU-Linux/_ext/73c876dd/FiducialPoints.o build/Debug/GNU-Linux/_ext/73c876dd/Generic.o build/Debug/GNU-Linux/_ext/73c876dd/GeometryLib.o build/Debug/GNU-Linux/_ext/73c876dd/Grid.o build/Debug/GNU-Linux/_ext/73c876dd/Histogram.o build/Debug/GNU-Linux/_ext/73c876dd/ImageProcessing.o build/Debug/GNU-Linux/_ext/73c876dd/L_algbra.o build/Debug/GNU-Linux/_ext/73c876dd/MatrixLib.o build/Debug/GNU-Linux/_ext/73c876dd/NonlinearFit.o build/Debug/GNU-Linux/_ext/73c876dd/PDLIO.o build/Debug/GNU-Linux/_ext/73c876dd/Processing.o build/Debug/GNU-Linux/_ext/73c876dd/RFunctions.o build/Debug/GNU-Linux/_ext/73c876dd/ROI.o build/Debug/GNU-Linux/_ext/73c876dd/ShellGeneric.o build/Debug/GNU-Linux/_ext/73c876dd/TwoDTriangulation.o build/Debug/GNU-Linux/_ext/73c876dd/VectorLib.o build/Debug/GNU-Linux/_ext/73c876dd/VolumeProcessing.o build/Debug/GNU-Linux/_ext/73c876dd/VolumeRotation.o build/Debug/GNU-Linux/_ext/73c876dd/colour.o build/Debug/GNU-Linux/_ext/73c876dd/correlation.o build/Debug/GNU-Linux/_ext/73c876dd/fft.o build/Debug/GNU-Linux/_ext/73c876dd/wirth.o build/Debug/GNU-Linux/_ext/73c876dd/xmlReader.o build/Debug/GNU-Linux/main.o /usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lpng

I get the following error message.

/home/peter/NetBeansProjects/ApplyModelToSet/../../DraculaFiles/CWebImageIO.cpp:247: undefined reference to `cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int ...
(more)
edit retag flag offensive close merge delete

Comments

imwrite is in imgcodecs lib. You must add something like -lopencv_imgcodecs (sorry I know only window name)

LBerger gravatar imageLBerger ( 2017-04-30 07:45:39 -0500 )edit

Thank you for your reply. Unfortunately, a search for imgcodecs, on my system, returned only directories and .cpp or .h files. No libraries. On Linux, the "pkg-config opencv --libs" command lists all the libraries I have for OpenCV. Thanks,

OtagoHarbour gravatar imageOtagoHarbour ( 2017-04-30 11:53:58 -0500 )edit

may be build opencv using cmake will solve your problem.

LBerger gravatar imageLBerger ( 2017-04-30 12:01:13 -0500 )edit

there is neither an opencv_contrib lib nor an opencv_legacy one with opencv3.2, those are from outdated opencv2.4. please check, what you really have there.

using opencv2.4 you'd have to link -lopencv_highgui for imwrite()

berak gravatar imageberak ( 2017-05-01 01:29:28 -0500 )edit

I decided to link by adding $(pkg-config opencv --libs) to the end of the build command instead of specifying libraries. I still get the same error for imwrite. What library contains inwrite for opencv3.2? Thanks,

OtagoHarbour gravatar imageOtagoHarbour ( 2017-05-01 21:31:43 -0500 )edit