Storing multiple image frames in a 4 D unit
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a while loop that aquires images from 2 seperate IP cameras (which works fine).
the images are to be stored in a 4D-unit so that every frame occupies one indes in the 4th dimension of that unit.
Despite the frames showing an image (using imshow to verify) the final 4D units only contains black frames.
while toc(startTime) < videoDuration
% Acquire frames from each camera
frame1 = getsnapshot(camA);
frame2 = getsnapshot(camB);
% frame1 = im2gray(frame1);
% frame2 = im2gray(frame2);
% Store frames in the 4D matrices for each camera
videoDataCam1(:, :, :,frameIndex) = frame1;
videoDataCam2(:, :, :,frameIndex) = frame2;
frameIndex = frameIndex + 1;
end
I assume i have some glaring error in my Syntax; especcially in the lines where the array is supposed to be written in. If you find it, i would be thankful for an answer.
3 comentarios
Frederik Vogel
el 17 de Nov. de 2023
Movida: Dyuman Joshi
el 17 de Nov. de 2023
DGM
el 17 de Nov. de 2023
Unless getsnapshot() is somehow locked to the framerate (which I don't think it is), I don't see anything here that controls how many frames get captured. So you'll either get less than 300, or more than 300 frames. It's unlikely that you'll reliably get exactly 300 frames.
If you want a fixed number of frames, I don't know why you don't just capture a fixed number of frames (use a for loop) instead of relying on the loop timing to be exact.
I gave up trying to get videoinput() to work with my capture card, so this isn't something I can test.
Respuestas (1)
Nipun
el 26 de Dic. de 2023
Hi Frederik,
I understand that you are trying to save the video frames in a four dimensional matrix for computation later, but are getting black frames on retrieving the frames.
Based on the information provided, it looks like you are using "BayerBG8" format for camA and "Mono8" format for camB. The BayerBG8 format needs to be converted to RGB before storing it in a 4D matrix. Additionally, you need to make sure that the data type and range of the images are compatible with the expected format.
Here's an updated version of your code that should handle these issues:
% ... (Your previous code)
% Initialize the 4D matrices to store frames for each camera
videoDataCam1 = zeros(szA1, szA2, 3, round(videoDuration * 30), 'uint8'); % Assuming 30 frames per second
videoDataCam2 = zeros(szB1, szB2, 3, round(videoDuration * 30), 'uint8'); % Assuming 30 frames per second
% Start the cameras
start(camA);
start(camB);
% Record the videos
frameIndex = 1;
startTime = tic;
while toc(startTime) < videoDuration
% Acquire frames from each camera
frame1 = getsnapshot(camA);
frame2 = getsnapshot(camB);
% Convert BayerBG8 to RGB for camA
frame1 = demosaic(frame1, 'rgb');
% Convert Mono8 to RGB for camB
frame2 = cat(3, frame2, frame2, frame2);
% Store frames in the 4D matrices for each camera
videoDataCam1(:, :, :, frameIndex) = frame1;
videoDataCam2(:, :, :, frameIndex) = frame2;
frameIndex = frameIndex + 1;
end
% ... (Your code continues)
In this version, I added the conversion from BayerBG8 to RGB using the demosaic function for camA. For camB, I used the cat function to create an RGB image from the single-channel Mono8 image. I also specified the data type as 'uint8' when initializing the 4D matrices to ensure compatibility.
Link to documentation:
- cat in MATLAB - https://www.mathworks.com/help/matlab/ref/double.cat.html
- demosaic in MATLAB - https://www.mathworks.com/help/images/ref/demosaic.html
Hope this helps.
Regards,
Nipun
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!