Hi,
I have a large text file which has data in below format
frame_count: 1, frame_type: p, mv_dst: (8, 8), mv_src: (8, 8), mv_type: f, motion: (0, 0, 4), mb: (16, 16)
frame_count: 1, frame_type: p, mv_dst: (24, 8), mv_src: (24, 8), mv_type: f, motion: (0, 0, 4), mb: (16, 16)
and so on.
I want to extract the value of mv_dst,mv_src and first two numbers of value motion and store in a matrix in below format
frame_count: 1, frame_type: p, mv_dst: (8, 8), mv_src: (8, 8), mv_type: f, motion: (0, 0, 4), mb: (16, 16)
Matrix should have value like this
first matrix with value from mv_dst(8,8) and first value from motion motion: (0, 0, 4) [ 0 in this case]
x_vec y_vec motion
8 8 0
second matrix with value from mv_src(8,8) and second value from motion :motion: (0, 0, 4) [ 0 in this case]
x_vec y_vec motion
8 8 0

 채택된 답변

Akira Agata
Akira Agata 2020년 4월 21일

0 개 추천

How about the following?
% Read the original text file
c = readcell('data.txt','Delimiter','\n');
% Extract coordinates from each line
cData = regexp(c,'\d+,\s+\d+(,\s+\d+)*','match');
cData = vertcat(cData{:});
% Arrange the numbers
mv_dst = str2double(split(cData(:,1),','));
mv_src = str2double(split(cData(:,2),','));
motion = str2double(split(cData(:,3),','));
% 1st and 2nd matrix
T1 = array2table([mv_dst,motion(:,1)],'VariableNames',{'x_vec','y_vec','motion'});
T2 = array2table([mv_src,motion(:,2)],'VariableNames',{'x_vec','y_vec','motion'});

댓글 수: 5

ImageAnalyst
ImageAnalyst 2020년 4월 21일
I am getting below error
error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in ffmpeg_motion_vectors (line 14)
cData = vertcat(cData{:});
Perhaps the problem is with regexp expression
Akira Agata
Akira Agata 2020년 4월 21일
If your data file is similar to the attached 'data.txt', the code should work.
I think this error was caused by some anomaly in your data file.
So, if possible, could you upload your data file which generate the error ?
ImageAnalyst
ImageAnalyst 2020년 4월 21일
Hello Akira,
The file itself is too large to attach even after zipping. I have extracted motion vectors using FFmpeg in a text file. So it has motion vectors for every position in every frame. There are around 5000 frames in my video file. I am attching the data for 1st frame that is being extracted.
ImageAnalyst
ImageAnalyst 2020년 4월 21일
I tested myself with this text.txt and the above code works fine its only when using the whole file that i get the error.I have attched the file. Could you please take a look
Akira Agata
Akira Agata 2020년 4월 22일
Hi Arya-san,
Thank you for sharing the file. But, unfortunately, I could not unzip the file. Could you upload the file (original file or newly zipped file) again?

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

질문:

2020년 4월 20일

댓글:

2020년 4월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by