Insert variable into video in Matlab

时间:2015-10-30 23:38:05

标签: matlab video-processing matlab-cvst

I currently have two scripts. One that plots luminescence of a pixel in a video over time and another that horizontally merges two videos. The first video is an original video and the second is the same video that has been previously processed. I wanted to insert the luminescence variable over the second video in the comparison video, in the bottom right hand corner. I think I may have gotten lost somewhere though: close all clc clear vid1 = VideoReader('original.avi'); vid2 = VideoReader('result.avi'); videoPlayer = vision.VideoPlayer; row = vid2.Height/3; col = vid2.Width/2; outputVideo = VideoWriter('comparison.avi'); outputVideo.FrameRate = vid1.FrameRate; open(outputVideo); while hasFrame(vid1) && hasFrame(vid2) result_vid = readFrame(vid2); r = result_vid(row, col, 1); g = result_vid(row, col, 2); b = result_vid(row, col, 3); lum = 0.2126 * r + 0.7152 * g + 0.0722 * b; L = [L lum]; text_str = L; position = [vid2.Width 10]; original_vid = readFrame(vid1); imgt = horzcat(original_vid, result_vid); plot(L) ylim auto xlim([0 600]); % play video step(videoPlayer, imgt); RGB = insertText(imgt,position,text_str); % record new video writeVideo(outputVideo, imgt); end release(videoPlayer); close(outputVideo); Any help would be great!

1 个答案:

答案 0 :(得分:0)

您正在将imgt中包含的框架写入视频文件。您的注释包含在RGB变量中。

writeVideo(outputVideo, RGB);

应该修复它。