Ask Your Question
0

Best way to save CV_16SC3 frames

asked 2017-02-15 04:42:30 -0600

victor.dmdb gravatar image

VideoWriter doesn't seem to have any 16bit codecs (or am I wrong about that?), so should these be saved with FileStorage instead? Assuming I need to save 16bit images at 25+ fps.

I'm actually trying to save an 8U, 16U and 16S at the same time, so I just merge all three into an CV_16SC3 Mat. Or is there a better solution to this?

edit retag flag offensive close merge delete

Comments

I'm actually trying to save an 8U, 16U and 16S at the same time, so I just merge all three into an CV_16SC3 Mat.

why on earth would you need that ? also, you cannot save different datatypes in the same image, you you'd have to convert them to a common type anyway.

berak gravatar imageberak ( 2017-02-15 05:09:47 -0600 )edit

Need to store different data types to hold multiple data sources for each frame. All the data have the same resolution. Yep I was converting them to 16S before merging anyway.

victor.dmdb gravatar imagevictor.dmdb ( 2017-02-15 07:00:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2017-02-15 05:41:36 -0600

kbarni gravatar image

updated 2017-02-15 05:45:42 -0600

As Berak said, it's not a good idea to combine these images into a single 3 channel image. You make unnecessary memory operations and disk writing.

For vodeo files (avi or similar) there are no 16 bit codecs. You can save a series of 8 and 16 bit TIF files, but I think it's quite slow, so it won't work at 25+ fps.

The best way to do this (especially if the image size is known) would be to dump directly the data to the disk. Something like (c++ code, only with two frames to keep things simple):

ofstream myfile;
myfile.open ("video.dat",ios::binary);
uchar *frame1=new uchar[w*h];
ushort *frame2=new ushort[w*h];
Mat i1(w,h,frame1,CV_8UC1);
Mat i2(w,h,frame2,CV_16UC1);
....
myfile.write(frame1,w*h);
myfile.write(frame2,w*h*2);
...//repeat for every frame
myfile.close();

When reading the data, just do the opposite operations:

while(!myfile.eof()){
    myfile.read(frame1,w*h);
    myfile.read(frame2,w*h*2);
}

By knowing the size of a data chunk (sizeof(frame1)+sizeof(frame2)+...), you can jump directly to a given frame, too.

If the image size can vary, you can write these parameters as the first bytes of the file.

edit flag offensive delete link more

Comments

Also sorry, the fps thing wasn't related to the speed, but most just stating i'm storing large 16bit matrices at a high rate. My concern would actually more be towards compression than speed.

victor.dmdb gravatar imagevictor.dmdb ( 2017-02-15 07:45:14 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-15 04:42:30 -0600

Seen: 1,180 times

Last updated: Feb 15 '17