How to get RGB-values out of video frames using VideoReader-function. When reading an individual frame using impixel-function I get only 3 times zero for RGB.

조회 수: 3 (최근 30일)
videoObject = VideoReader('TypeI_4_1_TestClipped.wmv');
imageData = read(videoObject);
numFrames = get(videoObject, 'NumberOfFrames');
Heig= get(videoObject, 'Height');
Wid= get(videoObject, 'Width');
Rateframe= get(videoObject, 'FrameRate');
time=get(videoObject, 'Duration');
% To cut down the time for this trial height and width are reduced
Wid=200;
Heig=100;
Hii = Heig*(ones(1,Wid));
mov(10).cdata = read(videoObject,10);
P1=impixel(mov(10).cdata,wii,Hii);
% or
imagedata=read(videoObject,10);
P2=impixel(mov(10).cdata,wii,Hii);
% Both P1 and P2 appear to became 200 x 3 full of zeros
  댓글 수: 4
Pekka Koivisto
Pekka Koivisto 2015년 7월 2일
There was more than one error in the code I sent - however it did not affect the problem. Here is what I tried: videoObject = VideoReader('TypeI_4_1_TestClipped.wmv'); imageData = read(videoObject);
numFrames = get(videoObject, 'NumberOfFrames');
Heig= get(videoObject, 'Height');
Wid= get(videoObject, 'Width');
Rateframe= get(videoObject, 'FrameRate');
time=get(videoObject, 'Duration');
% To cut down the time for this trial height and width are reduced
Wid=200;
Heig=100;
Hii = Heig*(ones(1,Wid));
wii=200;
mov(10).cdata = read(videoObject,10);
P1=impixel(mov(10).cdata,wii,Hii);
% or
imagedata=read(videoObject,10);
P2=impixel(imageData,wii,Hii);
% Both P1 and P2 appear to became 200 x 3 full of zeros
Pekka Koivisto
Pekka Koivisto 2015년 7월 3일
I have now solved my problem. It was not in the code but in the video. During the cropping process I had not taken into account that the frame size DOES NOT shrink, but the rest of the frame is black, which is in RGB=0, 0, 0. So now when I focused the pixels correctly I received the real RGB values ! Thanks for everyone participating the problem. With best regards Pekka Koivisto

댓글을 달려면 로그인하십시오.

채택된 답변

Nalini Vishnoi
Nalini Vishnoi 2015년 7월 2일
Hi Pekka,
I understand that you would like to get the RGB values out of video frames using 'VideoReader' and 'impixel' function. As other users have pointed out there is some ambiguity in your example code, hence I am unable to test it. Please find a small example below demonstrating the use of 'VideoReader' and 'impixel' functions to read the RGB value of a frame:
>> xyloObj = VideoReader('xylophone.mp4');
>> frame = read(xyloObj,10); % reading the 10th frame
>> c = 200;
>> r = 100;
>> rgb = impixel(frame, c, r); % returns the RGB value of column 200 and row 100
>> c = 101:200;
>> r = 1:100;
>> rgb = impixel(frame, c, r); % returns the RGB values of frame(r,c). Here r and c are vectors
I hope the above example helps. You can find more information about how impixel function works in the documentation link here.
Thanks,
Nalini
  댓글 수: 1
Pekka Koivisto
Pekka Koivisto 2015년 7월 2일
Yes in the code I sent wii was not defined HOWEVER that was not the issue here. I copy pasted the code Nalini sent me and tested it with the video (wmv) file I am struggling with (yes it has been checked to be full of other than 0 rgb:s) and once again I received a matrix full of zeros. So unfortunately this code did not help me in my problem. All the best Pekka Koivisto

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by