#include <fstream>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <vector>
int main()
{
std::string filename = "/media/dingxin/data/study/OpenCV/sources/images/hawk.jpg";
std::ifstream file( filename, std::ios::binary );
if ( !file.is_open() )
{
std::cout << "Failed to open file." << std::endl;
return -1;
}
std::vector< unsigned char > buffer( ( std::istreambuf_iterator< char >( file ) ), std::istreambuf_iterator< char >() );
file.close();
cv::Mat img = cv::imdecode( buffer, cv::IMREAD_COLOR );
if ( img.empty() )
{
std::cout << "Failed to decode image data." << std::endl;
return -1;
}
cv::imshow( "Decoded Image", img );
cv::waitKey( 0 );
return 0;
}