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 );
}
Yes, you shall do some kind of image name generator, so you'll have a different filename each call of imwrite. For eg:
int i=0; std::string savingName = filename + std::to_string(i) + extension;
//to check if the file exist
@sturkmen: but this way, it will not save the image, if it exists...
I am using a name generator for the image filename... Problem is that I forget to move the files after a run.. Then I start up the application again and overwrite my previous run...
I have tried the cvHaveImageReader() and it works as @sturkmen stated above... However, is there any documentation on this function...? I can't find anything.. Thanks,
@thdrksdfthmn you are right. i only wanted to mention that we can use
cvHaveImageReader(filename)
to determine if the file exist.int cvHaveImageReader ( const char * filename )
determine can opencv open an image file or not.Why C-API???And more, you shall use cvHaveImageWriter, no? There is no doc for it...