我在Ubuntu 64位上使用OpenCV 3.2.0并且编写了以下代码,我称之为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;
}
然后我尝试使用以下内容构建它。
g++ `pkg-config opencv --libs` -o dist/Debug/GNU-Linux/progName build/Debug/GNU-Linux/_ext/73c876dd/WebImageIO.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
我收到以下错误消息。
/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&)'
我已经读过cv :: imread(至少)使用imgcodecs库但是
sudo find / -name '*imgcodecs*.so' -print
在我的系统上安装opencv 3.2后,没有返回任何结果
编辑:
pkg-config opencv --libs
返回
/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