Disable file system cache during imwrite

asked 2020-08-07 07:58:14 -0500

I am trying to build a application with opencv and c++ in Linux env to capture and save 10000 images, But after saving 800 images System buff/cache is increasing and application running slow (system getting hanged up). Is there any way to disable file system cache or clear cache after imwrite or save image without using imwrite. (want to store in .bmp format)

any suggestion will be helpful, Thankyou

edit retag flag offensive close merge delete



Is this really an OpenCV issue? What do you mean by system buff/cache? Memory? Can you post a minimal example of your code?

Der Luftmensch gravatar imageDer Luftmensch ( 2020-08-07 09:53:16 -0500 )edit

If the system has a cache, the problem is that your hard drive becomes the bottleneck aften the cache fills up. Obviously, you can find a library or source code to write any format you like, but it is unlikely to bring any speed benefit - especially with BMP, which is the very worst in that regard. Perhaps you could write JPEGs and in a separate process convert them to BMPs.

mvuori gravatar imagemvuori ( 2020-08-07 14:23:48 -0500 )edit

seems to be a limitation of your os (and has to be handled from there)

i'm quite sure you can reproduce it with just writing 800 images to disk (w/o using imwrite)

berak gravatar imageberak ( 2020-08-08 01:39:31 -0500 )edit

Code snippet:

int count = 0;
unsigned char * buff = NULL;
cv::Mat matt(800, 1280, CV_8UC4);
cv::Mat mat;
while(count < 10000) {
    buff = captureFrame(); // Using V4L2 to capture frame
    memcpy(matt.data, buff, 1280*800*4);
    cv::cvtColor(matt, mat, cv::COLOR_BGRA2BGR);
    sprintf(file_name, "./camera_images_data/frame%d.bmp", count);
    cv::imwrite(file_name, mat);

This is the code snippet I am using

Supreeth Kumar Y P gravatar imageSupreeth Kumar Y P ( 2020-08-12 01:48:09 -0500 )edit

@Der Luftmensch, As per Requirement I need to use either png or bmp.

Supreeth Kumar Y P gravatar imageSupreeth Kumar Y P ( 2020-08-12 01:50:29 -0500 )edit