本文整理汇总了C++中ImageEncoder::write方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageEncoder::write方法的具体用法?C++ ImageEncoder::write怎么用?C++ ImageEncoder::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageEncoder
的用法示例。
在下文中一共展示了ImageEncoder::write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: imencode
bool imencode( const String& ext, InputArray _image,
std::vector<uchar>& buf, const std::vector<int>& params )
{
CV_TRACE_FUNCTION();
Mat image = _image.getMat();
int channels = image.channels();
CV_Assert( channels == 1 || channels == 3 || channels == 4 );
ImageEncoder encoder = findEncoder( ext );
if( !encoder )
CV_Error( CV_StsError, "could not find encoder for the specified extension" );
if( !encoder->isFormatSupported(image.depth()) )
{
CV_Assert( encoder->isFormatSupported(CV_8U) );
Mat temp;
image.convertTo(temp, CV_8U);
image = temp;
}
bool code;
if( encoder->setDestination(buf) )
{
code = encoder->write(image, params);
encoder->throwOnEror();
CV_Assert( code );
}
else
{
String filename = tempfile();
code = encoder->setDestination(filename);
CV_Assert( code );
code = encoder->write(image, params);
encoder->throwOnEror();
CV_Assert( code );
FILE* f = fopen( filename.c_str(), "rb" );
CV_Assert(f != 0);
fseek( f, 0, SEEK_END );
long pos = ftell(f);
buf.resize((size_t)pos);
fseek( f, 0, SEEK_SET );
buf.resize(fread( &buf[0], 1, buf.size(), f ));
fclose(f);
remove(filename.c_str());
}
return code;
}
示例2: imwrite_
static bool imwrite_( const string& filename, const Mat& image,
const vector<int>& params, bool flipv )
{
Mat temp;
const Mat* pimage = ℑ
CV_Assert( image.channels() == 1 || image.channels() == 3 || image.channels() == 4 );
ImageEncoder encoder = findEncoder( filename );
if( encoder.empty() )
CV_Error( CV_StsError, "could not find a writer for the specified extension" );
if( !encoder->isFormatSupported(image.depth()) )
{
CV_Assert( encoder->isFormatSupported(CV_8U) );
image.convertTo( temp, CV_8U );
pimage = &temp;
}
if( flipv )
{
flip(*pimage, temp, 0);
pimage = &temp;
}
encoder->setDestination( filename );
bool code = encoder->write( *pimage, params );
// CV_Assert( code );
return code;
}