Single Marker 3D Coordinate Streaming Matlab

Post Reply
limo1234
Posts: 2
Joined: Wed Jun 15, 2022 9:51 am

Single Marker 3D Coordinate Streaming Matlab

Post by limo1234 »

Hello,
I'm currently working on a soft body tracking project with my university and need to stream the 3D coordinates of individual markers not placed in a rigid body. I've been reading through the numerous forums but still am very confused as to how I can obtain an unlabeled marker coordinate in Matlab. The samples provide a rigidbody framework but I need to keep markers individual. What are the functions I can call to obtain the marker data?

Thank you so much!
limo1234
Posts: 2
Joined: Wed Jun 15, 2022 9:51 am

Re: Single Marker 3D Coordinate Streaming Matlab

Post by limo1234 »

%put file in Matlab folder
function MarkerTracking
clc
clear
cla
fprintf( 'Start\n' )
fprintf( '=========================================================\n' )
pause(2);
fprintf( 'Connecting...\n' )
pause(1);
natnetclient = natnet;
natnetclient.HostIP = 'IP HERE';
natnetclient.ClientIP = 'IP HERE';
natnetclient.ConnectionType = 'Multicast';
natnetclient.connect;
if ( natnetclient.IsConnected == 0 )
fprintf( 'Failed to connect\n' )
return
else
fprintf( 'Connected\n' )
pause(1);
end
addpath( 'event handlers')
natnetclient.addlistener( 1 , 'MarkerTrackingF' );
natnetclient.enable(0)
fprintf( 'Enter any key to quit\n' )
pause;
fprintf( '=========================================================\n' )
natnetclient.disable(0)
disp('End' )
pause(1)
end

-------------------------------------------------------------------------------------------------------------------------------------------

%put file in event handlers folder
function MarkerTrackingF( ~ , evnt )
cla
for i = 1 : evnt.data.nMarkers
x(i) = double( evnt.data.LabeledMarkers(i).x );
y(i) = double( evnt.data.LabeledMarkers(i).y );
z(i) = double( evnt.data.LabeledMarkers(i).z );
end

plot3(z,x,y,'.')
%$line(x(1),y(1),'Color','red','LineStyle','--')
%disp(x.(1));
xlabel('X')
ylabel('Z')
zlabel('Y')
xlim([-1.5 1.5])
ylim([-1.5 1.5])
zlim([0 5])
set(groot,'defaultLineMarkerSize',10);
hold on
grid on

end
Post Reply