I'm a newbie on openCV.
I just downloaded the source of openCV from Github and installed it on the desktop (Mac OS).
Now I need to do convert a binary file to an image file. Here is the code:
// The program is first to convert the image to the binary file then convert the binary file back to the image
#include <iostream>
#include </Users/Me/Desktop/opencv-master/include/opencv2/opencv.hpp>
#include </Users/Me/Desktop/opencv-master/modules/highgui/include/opencv2/highgui.hpp>
const std::string filename = "test.dat";
const std::string picname = "pano_b.jpg";
int main(int argc, char **argv)
{
std::ofstream outfile;
outfile.open(filename.c_str(), std::ios::binary);
if (!outfile)
{
std::cerr << "failed to open the file : " << filename << std::endl;
return -1;
}
cv::Mat srcImg = cv::imread(picname);
if (srcImg.empty())
{
std::cerr << "failed to open the file : " << picname << std::endl;
return -1;
}
for (int r = 0; r < srcImg.rows; r++)
outfile.write(reinterpret_cast<const char*>(srcImg.ptr(r)), srcImg.cols*srcImg.elemSize());
std::cout << "write to file ok!" << std::endl;
///// Here the file test.dat is generated. It looks like this:
///// 0069 a800 6caa 0074 af0c 80b9 2096 ca2a
///// 9fd2 1c8d bf03 71a1 0773 a300 6295 0064
///// 9907 73a9 0070 a900 6da8 0480 bc18 95d2
///// ...
//////// Now I want to convert test.dat into an image file
cv::Mat img = cv::imread(filename.c_str(), cv::IMREAD_ANYCOLOR);
cv::imshow("img", img);
cv::waitKey();
return 0;
}
However I got an error as below:
Undefined symbols for architecture x86_64: "cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from: _main in bbb-bb77f0.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
As I said, I installed the openCV on the desktop, here is how I compile:
g++ test.cpp /Users/Me/Desktop/opencv-master/build/lib/libopencv_core.dylib /Users/Me/Desktop/opencv-master/build/lib/libopencv_imgproc.dylib /Users/Me/Desktop/opencv-master/build/lib/libopencv_imgcodecs.dylib
Here is all lib files that I found in the openCV directory:
What should I do to solve this link error?