Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv::imwrite “undefined” when using OpenCV 3.2

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, std::allocator<int> > const&)'

I have read that cv::imread (at least) uses the imgcodecs library but

 sudo find / -name '*imgcodecs*.so' -print

returns no results after my having installed opencv 3.2 on my system

$ pkg-config opencv --libs

returns

/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d /usr/lib/x86_64-linux-gnu/libopencv_contrib.so -lopencv_contrib /usr/lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core /usr/lib/x86_64-linux-gnu/libopencv_features2d.so -lopencv_features2d /usr/lib/x86_64-linux-gnu/libopencv_flann.so -lopencv_flann /usr/lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu /usr/lib/x86_64-linux-gnu/libopencv_highgui.so -lopencv_highgui /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so -lopencv_imgproc /usr/lib/x86_64-linux-gnu/libopencv_legacy.so -lopencv_legacy /usr/lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml /usr/lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect /usr/lib/x86_64-linux-gnu/libopencv_ocl.so -lopencv_ocl /usr/lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo /usr/lib/x86_64-linux-gnu/libopencv_stitching.so -lopencv_stitching /usr/lib/x86_64-linux-gnu/libopencv_superres.so -lopencv_superres /usr/lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts /usr/lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video /usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_videostab