使用Facebook的OpenPose库,我生成了渲染的RGB图像和JSON文件。现在,从JSON文件中,我想形成感兴趣的人的2D骨架。但是在JSON文件中,检测到多个框架,有时甚至检测到错误的框架。如何跟踪感兴趣的人并从中形成2D骨架?
在图像(下面的链接)中,我给出了示例图像。 这是我定义的功能。在这种情况下,我试图从左侧找到JSON的最小值,并使用该JSON值形成一个2D骨架。
Link to sample images and JSON
function mat_files(json,mat)
filePattern = fullfile(json, '*.json');
file = dir(filePattern);
for m = 1:length(file)
JsonDataBase = file(m).name;
JsonData = fullfile(json, JsonDataBase);
S2 = loadjson(JsonData);
b1 = converting1(S2);%Converts all keypoints of persons detected in column format
if b1 ==0
else
Zo = b1;
Zo(: ,Zo(9,:) == 0 | Zo(11,:) == 0 | Zo(12,:) == 0 | Zo(14,:) == 0 | Zo(15,:) == 0 | Zo(10,:) == 0 | Zo(13,:)== 0 ) = NaN;
Zo(Zo == 0) = NaN;
a21 = min(Zo(:,1:2:end),[],1); %x values
a211 = min(Zo(:,2:2:end), [],1); %y Values
a22 = a21((a21 > 600 & a21 <1100) & ( a211 <700));
%a222 = a222(a222 > 500 & a222 <1700);
a2 = min(a22) ;
%a23 = min(a222)
if isempty(a2)
continue
else
[x,y]=find(a2==Zo);
A=Zo(:,y:y+1); % Gives only one set of keyjoints which is first from left.
A(isnan(A)) = 0;
b2 =int64(round(A));
end
end
baseFileName2 = sprintf('%s.mat', JsonDataBase );
fullFileName2 = fullfile(mat, baseFileName2);
save(fullFileName2,'b2')
end
上面使用的转换函数如下:
function b1 = converting1(S)
a = zeros(1,54, 'uint8') ;% a= 1x54 uint8 row vector
b = zeros(25,3, 'double') ;% b is 14x3 double matrix
K = S.people;
if isempty(K)
b1=0;
else
J = cell2mat(K);
c = size(J,2);
f=1;
b1 = zeros(25 , c*2);
for i = 1:size(J,2)
A = J(i).pose_keypoints_2d;
A1 = A(1,1:75);
n = 1;
for C2 = 1:25
for C3 = 1:3
b(C2,C3) = A1(n);
n = n+1;
end
end
b1(:,f:f+1) = b(1:25,1:2) ;
f=f+2;
end
end