Ask Your Question
-1

Disable file system cache during imwrite [closed]

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

Supreeth Kumar Y P gravatar image

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 reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by supra56
close date 2020-09-25 09:38:59.897771

Comments

1

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 -0600 )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 -0600 )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 -0600 )edit
1

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);
    count++;
}

This is the code snippet I am using

Supreeth Kumar Y P gravatar imageSupreeth Kumar Y P ( 2020-08-12 01:48:09 -0600 )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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-09-25 07:49:08 -0600

Supreeth Kumar Y P gravatar image

By using jpeg my problem solved. Thank you!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-08-07 07:58:14 -0600

Seen: 1,910 times

Last updated: Sep 25 '20