Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is there a way to keep imwrite from overwriting files..?

Using the latest OpenCV 3.0 on a Linux platform. Using the following to write out image files. However it is more than happy to overwrite an existing file... Is there a mechanism to keep imwrite() from overwriting files...?

/* Create parameters */
vector<int> params;
if( fileExt.compare( "png" ) == 0 )
{
    params.push_back( IMWRITE_PNG_COMPRESSION );
    params.push_back( png_compress_level );
}

/* Try to write image */
try
{
    imwrite( filename, *img, params );
}
catch (runtime_error& ex) 
{
    fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
    return( 0 );
}