Ask Your Question
0

Speeding up reading PNG images

asked 2020-11-18 05:32:03 -0500

OpenCV version: 4.5.0, compiled from source in release mode with static libraries; Operating system: Ubuntu 18.04;

I am working on optimizing a reasonably computationally-expensive computer vision application and have reached a point where it seems like loading up a dataset takes 20-25% of the time.

I am loading RGB-D pairs stored as PNG sequentially (pre-loading all images is not an option). imread averages 4ms / image (and internally, png_read_image is only a few ns faster).

Any suggestions on how I could speed this up, please?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-11-18 08:23:46 -0500

kbarni gravatar image

PNG compression is computationally expensive. If this is a bottleneck of your application, you should choose another file format (like TIFF, which is read faster and can store 8 bit and 16 bit data, so it's well suited to store RGB-D data) or even uncompressed raw data.

Writing/reading RAW data is something like this (in pure C, can be adapted to other languages):

cv::Mat imgRGB,imgD;
//...acquire the images...
FILE *fptr;
fptr = fopen("imageRGB.dat","wb");
fwrite(imgRGB.ptr(0),3,imgRGB.cols*imgRGB.rows,fptr);
fclose(fptr);
fptr = fopen("imageD.dat","wb");
fwrite(imgD.ptr(0),2,imgD.cols*imgD.rows,fptr);
fclose(fptr);
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-11-18 05:32:03 -0500

Seen: 37 times

Last updated: Nov 18