Effacer les filtres
Effacer les filtres

How to play 16uint video?

1 vue (au cours des 30 derniers jours)
Pien Vinke
Pien Vinke le 8 Mai 2023
Dear Community,
I am recording a video with a Thermal camera (gige). The recorded data has a 16uint format. When playing the video with the implay command, the video file format is transfered to 8uint, in where all the data is being devided by 256. Due to this process, I only get the same intensity value (206) and thus all the details of the video are being lost. Does someone know how to play a 16uint video in Matlab? Attached you can find my script.
clear all, clc, close all
Winvideoinfo = imaqhwinfo('winvideo');
Gigeinfo = imaqhwinfo('gige');
% imaqmex('feature','-limitPhysicalMemoryUsage',false);
v1 = videoinput('winvideo','2');
v2 = videoinput('gige');
s1 = v1.Source;
s2 = v2.Source;
%%
triggerconfig(v1, 'manual');
triggerconfig(v2, 'manual');
amount_frames = 200;
v1.FramesPerTrigger = amount_frames;
v2.FramesPerTrigger = amount_frames;
v1.LoggingMode = 'disk&memory';
v2.LoggingMode = 'disk&memory';
subject_name1 = 'Visible_';
subject_name2 = 'Thermal_';
v1.DiskLogger = VideoWriter(subject_name1, 'Archival');
v2.DiskLogger = VideoWriter(subject_name2, 'Grayscale AVI');
v1.PreviewFullBitDepth = "off";
v2.PreviewFullBitDepth = "off";
%%
start([v1 v2]);
trigger([v1 v2]);
while strcmp(v1.Logging, 'on')
disp(v1.FramesAcquired)
pause(.1)
end
wait(v1, 1);
[frames1, timestamps1] = getdata(v1, v1.FramesPerTrigger);
[frames2, timestamps2] = getdata(v2, v2.FramesPerTrigger);
handle1 = implay(frames1);
handle2 = implay(frames2);
handle1.Parent.Position = [200 100 740 680];
handle2.Parent.Position = [940 100 740 680];
implay(handle1.DataSource.Controls)
implay(handle2.DataSource.Controls)
%%
delete(v2)
clear v2
delete(v1)
clear v1

Réponses (1)

Vinayak
Vinayak le 22 Mai 2023
You can leverage the "readFrame" function of the VideoReader class to store the frames in uint16 format. An example snippet can be as follows,
vid = VideoReader('myVideo.mp4');
while hasFrame(vid)
frame = readFrame(vid);
frames(:, :, :, vid.CurrentTime * vid.FrameRate) = uint16(frame);
end
vid_data = mat2gray(frames);
implay(vid_data);
Please note that playing a video without data compression can put a significant burden on memory usage and may impact video playback performance. Therefore, it is recommended to ensure that your system meets the required specifications to run the video in the specified format.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by