How can I write only every third element in the char buffer for quick download in C ++?
I get a three-channel image from my camera, but each channel contains the same information (grayscale image). I would like to record only one channel on a disc to save space and make recording faster, as it is part of a real-time data acquisition system.
The C ++ ofstream :: write command seems to write only continuous blocks of binary data, so my current code writes all three channels and is too slow:
char * data = getDataFromCamera(); int dataSize = imageWidth * imageHeight * imageChannels; std::ofstream output; output.open( fileName, std::ios::out | std::ios::binary ); output.write( data, dataSize );
I would like the last line to be replaced with the following call:
int skipSize = imageChannels; output.write( data, dataSize, skipSize );
where skipSize will force writing to put only every third in the output file. However, I could not find any function that does this.
I would like to hear any ideas for quickly getting one channel recorded to disk. Thank.
c ++ file-io
Ross Jul 20 2018-10-18T00: 00Z
source share