如何不经过文件,把char*格式的jpeg图转为opencv::Mat ?
关注者
5
被浏览
9,399
4 个回答
错了别怪我,我是看到问题后瞎试试的,或许有更好的办法
#include "D:/OpenCV-2.4.6/build/include/opencv2/core/core.hpp"
#include "D:/OpenCV-2.4.6/build/include/opencv2/highgui/highgui.hpp"
#ifndef NDEBUG
#pragma comment( lib, "D:/OpenCV-2.4.6/build/x86/vc9/lib/opencv_core246d.lib" )
#pragma comment( lib, "D:/OpenCV-2.4.6/build/x86/vc9/lib/opencv_highgui246d.lib" )
#else
#pragma comment( lib, "D:/OpenCV-2.4.6/build/x86/vc9/staticlib/opencv_core246.lib" )
#pragma comment( lib, "D:/OpenCV-2.4.6/build/x86/vc9/staticlib/opencv_highgui246.lib" )
#pragma comment( lib, "D:/OpenCV-2.4.6/build/x86/vc9/staticlib/IlmImf.lib" )
#pragma comment( lib, "D:/OpenCV-2.4.6/build/x86/vc9/staticlib/libjpeg.lib" )
#pragma comment( lib, "D:/OpenCV-2.4.6/build/x86/vc9/staticlib/libpng.lib" )
#pragma comment( lib, "D:/OpenCV-2.4.6/build/x86/vc9/staticlib/libtiff.lib" )
#pragma comment( lib, "D:/OpenCV-2.4.6/build/x86/vc9/staticlib/libjasper.lib" )
#pragma comment( lib, "D:/OpenCV-2.4.6/build/x86/vc9/staticlib/zlib.lib" )
#pragma comment( lib, "User32.lib" )
#endif
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
using namespace cv;
int main( void )
ifstream infile( ".\\a.bmp", ios::binary );
if( !infile )
return 1;
std::vector<char> data( (std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>() );
Mat test = imdecode( data, CV_LOAD_IMAGE_ANYDEPTH|CV_LOAD_IMAGE_ANYCOLOR );
imwrite( ".\\b.bmp", test );