main content

convert detections to objectdetection format -凯发k8网页登录

these examples show how to convert actual detections in the native format of the sensor into objectdetection objects. objectdetection is the standard input format for most tracking filters and trackers in the toolbox. the six examples progressively show how to set up objectdetection with varied tracking scenarios.

  • configures the detection in a stationary rectangular frame.

  • configures the detection in a moving rectangular frame.

  • configures the detection in a moving spherical frame.

  • shows how to express detections obtained by consecutive rotations.

  • shows how to configure 3-d detections.

  • shows how to configure classified detections.

an objectdetection report must contain the basic detection information: time and measurement. it can also contain other key properties, including measurementnoise, sensorindex, objectclassid, objectclassparameters, objectattributes, and measurementparameters. setting up measurementparameters correctly so that a filter or tracker can interpret the measurement is crucial in creating objectdetection. the first example shows the basic setup of an objectdetection. examples 2 through 5 focus on how to correctly set up measurementparameters. the last example shows how to set up objectclassparameters.

example 1: convert detections in stationary rectangular frame

consider a 2-d tracking scenario with a stationary tower and a truck. the tower located at the origin of the scenario frame is equipped with a radar sensor. at t = 0 seconds, the truck at the position of (10,20,0) meters is traveling in the positive x direction at a speed of 5 m/s.

the radar sensor outputs 3-d position and velocity measurements in the scenario frame, so the measurement can be written as follows:

measurement1 = [10;20;0;5;0;0]; % [x;y;z;vx;vy;vz]

you can specify additional properties such as measurmentnoise, sensorindex, objectclassid, and objectattributes for the objectdetection object. for example, assuming the standard deviation of the position and velocity measurement noise is 10 m and 1 m/s, respectively, you can define the measurement error covariance matrix as:

measurementnoise1 = diag([10*ones(3,1);ones(3,1)]);

create an objectdetection using these values.

time1 = 0; % detection time
detect1 = objectdetection(time1,measurement1,'measurementnoise',measurementnoise1)
detect1 = 
  objectdetection with properties:
                     time: 0
              measurement: [6x1 double]
         measurementnoise: [6x6 double]
              sensorindex: 1
            objectclassid: 0
    objectclassparameters: []
    measurementparameters: {}
         objectattributes: {}

example 2: convert detections in moving rectangular frame

consider a 2-d tracking scenario with an ego car and a truck. at t= 0 seconds, the car is located at (20,10,0) meters with respect to the scenario frame. the car is moving with a speed of 5 m/s in the y direction of the scenario frame. the local (forward) frame of the ego car, {x,y}, rotates from the scenario frame by an angle of 90 degrees. as in the previous example, a truck at the position of (10,20,0) meters is traveling in the positive x direction at a speed of 5 m/s.

meanwhile, the ego car is observing the truck in its own local frame, {x,y}. in practice, you can obtain the measurement directly from the sensor system of the ego car. from the figure, the measurements of the truck are [10; 10; 0 -5; -5; 0] with respect to the {x,y} frame in the order of [x;y;z;vx;vy;vz].

measurement2 = [10; 10; 0; -5;  -5; 0]; % [x;y;z;vx;vy;vz]

to specify the object detection, you need to specify the coordinate transformation from the scenario rectangular frame {x,y} to the local rectangular frame {x,y}. you can use the measurementparameters property of objectdetection to specify these transformation parameters. in the transformation, the scenario frame is the parent frame, and the ego car local frame is the child frame.

  • the frame property sets the child frame type to 'rectangular'(in this example) or 'spherical'.

  • the originposition property sets the position of the origin of the child frame with respect to the parent frame.

  • the originvelocity property sets the velocity of the origin of the child frame with respect to the parent frame.

mp2 = struct();
mp2.frame = 'rectangular'; 
mp2.originposition =[20; 10; 0]; 
mp2.originvelocity = [0; 5; 0]; 

specify rotation using the rotation matrix converted from euler angles. set isparenttochild to true to indicate rotation from the parent frame to the child frame.

rotangle2 = [90 0 0]; % [yaw,pitch,row]
rotquat2 = quaternion(rotangle2,'eulerd','zyx','frame');
rotmatrix2 = rotmat(rotquat2,'frame');
mp2.orientation = rotmatrix2;
mp2.isparenttochild = true; 

specify measurements.

  • set haselevation and hasazimuth both to false, since the child frame is rectangular.

  • set hasrange to true to enable position measurement.

  • set hasvelocity to true to enable velocity measurement.

mp2.haselevation = false;
mp2.hasazimuth = false;
mp2.hasrange = true;
mp2.hasvelocity = true;

create the objectdetection object and specify the measurementparameters property.

time2 = 0;
detection2 = objectdetection(time2,measurement2,'measurementparameters',mp2)
detection2 = 
  objectdetection with properties:
                     time: 0
              measurement: [6x1 double]
         measurementnoise: [6x6 double]
              sensorindex: 1
            objectclassid: 0
    objectclassparameters: []
    measurementparameters: [1x1 struct]
         objectattributes: {}

to verify the object detection, you can use the measurement function to regenerate the measurement. the cvmeas function can take the actual state of the target and measurement parameters as input. the state input of cvmeas is in the order of [x;vx;y;vy;z;vz]. as shown in the following output, the results agree with measurement2.

state2 =[10;5;20;0;0;0]; % state of truck in [x;vx;y;vy;z;vz]
cvmeas2 = cvmeas(state2,mp2) % measurement in [x;y;z;vx;vy;vz]
cvmeas2 = 6×1
   10.0000
   10.0000
         0
   -5.0000
   -5.0000
         0

example 3: convert detections in moving spherical frame

consider the previous tracking scenario, only now the measurement is obtained by a scanning radar with a spherical output frame. the boresight direction of the radar is aligned with the y direction (same as x direction) at t = 0 seconds.

since the relative velocity between the truck and the car is in the line-of-sight direction, the measurement, which is in the order of [azimuth; elevation; range; range-rate], can be obtained as follows:

measurement3 =[45; 0; 10/sind(45); -5/sind(45)]; % [az;el;rng;rr]. units in degrees.

specify the measurement parameters.

mp3 = struct();
mp3.frame = 'spherical'; % the child frame is spherical.
mp3.originposition = [20; 10; 0];
mp3.originvelocity = [0; 5; 0];
% specify rotation.
rotangle3 = [90 0 0];
rotquat3 = quaternion(rotangle3,'eulerd','zyx','frame');
rotmatrix3 = rotmat(rotquat3,'frame');
mp3.orientation = rotmatrix3;
mp3.isparenttochild = true; 

set haselevation and hasazimuth to true to output azimuth and elevation angles in the spherical child frame. set hasrange and hasvelocity both to true to output range and range-rate, respectively.

mp3.haselevation = true;
mp3.hasazimuth = true;
mp3.hasrange = true;
mp3.hasvelocity = true;

create the objectdetection object.

time3 = 0;
detection3 = objectdetection(time3,measurement3,'measurementparameters',mp3)
detection3 = 
  objectdetection with properties:
                     time: 0
              measurement: [4x1 double]
         measurementnoise: [4x4 double]
              sensorindex: 1
            objectclassid: 0
    objectclassparameters: []
    measurementparameters: [1x1 struct]
         objectattributes: {}

verify the results using cvmeas. the results agree with measurement3.

state3 = [10;5;20;0;0;0]; % [x;vx;y;vy;z;vz]
cvmeas3 = cvmeas(state3,mp3) % [az;el;rng;rr]
cvmeas3 = 4×1
   45.0000
         0
   14.1421
   -7.0711

example 4: convert detections between three frames

consider the previous tracking scenario, only now the boresight direction of the radar rotates 45 degrees from the x direction of the car's local frame.

the new measurements, expressed in the new spherical frame {x,y}, are:

measurement4 = [0; 0; 10/sind(45); -5/sind(45)]; % [az;el;rng;rr]

for the measurement parameters, you can specify the rotation as a 135-degree rotation from the scenario frame to the new spherical frame. alternately, you can specify it as two consecutive rotations: rectangular {x,y} to rectangular {x,y} and rectangular {x,y} to spherical {x,y}. to illustrate the multiple frame transformation feature supported by the measurementparameters property, this example uses the latter approach.

the first set of measurement parameters is exactly the same as mp2 used in . mp2 accounts for the rotation from the rectangular {x,y} to the rectangular {x,y}. for the second set of measurement parameters, mp4, you need to specify only a 45-degree rotation from the rectangular {x,y} to the spherical {x,y}.

mp4 = struct();
mp4.frame = 'spherical';
mp4.originposition =[0; 0; 0]; % colocated positions.
mp4.originvelocity = [0; 0; 0]; % same origin velocities.
% specify rotation.
rotangle4 = [45 0 0];
rotquat4 = quaternion(rotangle4,'eulerd','zyx','frame');
rotmatrix4 = rotmat(rotquat4,'frame');
mp4.orientation = rotmatrix4;
mp4.isparenttochild = true; 
% specify outputs in the spherical child frame.
mp4.haselevation = true;
mp4.hasazimuth = true;
mp4.hasrange = true;
mp4.hasvelocity = true;

create the combined measurementparameters input, mpc.

mpc =[mp4 mp2];

note that the sequence of measurement parameters matters here. the specified mpc represents first performing coordinate transformation corresponding to mp2 and then performing coordinate transformation corresponding to mp4.

next, create the objectdetection object.

time4 = 0;
detection4 = objectdetection(time4,measurement4,'measurementparameters',mpc)
detection4 = 
  objectdetection with properties:
                     time: 0
              measurement: [4x1 double]
         measurementnoise: [4x4 double]
              sensorindex: 1
            objectclassid: 0
    objectclassparameters: []
    measurementparameters: [1x2 struct]
         objectattributes: {}

verify the results using cvmeas. the result agrees with measurement4.

state4 = [10;5;20;0;0;0]; % [x;vx;y;vy;z;vz]
cvmeas4 = cvmeas(state4,mpc) % [az;el;rr;rrate]
cvmeas4 = 4×1
    0.0000
         0
   14.1421
   -7.0711

example 5: convert 3d detections

consider an unmanned aerial vehicle (uav) monitoring a region. at t = 0 seconds, the uav is at the position of (5,5,-1) km with respect to the global north-east-down (ned) frame. the velocity of the uav is (-50,-100,5) m/s. the orientation of the uav body frame {x,y,z} with respect to the global ned frame is given as (-120,2,2) degrees in yaw, pitch, and roll. at the same time, a car at the position of (1,1,0) km is moving east with a speed of 30 m/s. the uav measures the car using a radar system aligned with its own body axis.

based on this information, specify the kinematic parameters for the measurement transformation.

specify the frame type, origin position, and origin velocity of the uav body frame.

mp5 = struct();
mp5.frame = 'spherical'; 
mp5.originposition = [5000; 5000; -1000]; 
mp5.originvelocity = [-50; -100; 5]; 

specify the rotation from the ned frame to the uav body frame.

rot_angle5 = [-120 2 2]; % [yaw,pitch,roll]
rot_quat5 = quaternion(rot_angle5,'eulerd','zyx','frame');
rot_matrix5 = rotmat(rot_quat5,'frame');
mp5.orientation = rot_matrix5;
mp5.isparenttochild = true; 

specify the output measurements in a spherical frame.

mp5.haselevation = true;
mp5.hasazimuth = true;
mp5.hasrange = true;
mp5.hasvelocity = true;

you can obtain the measurement directly from the radar system on the uav. here, you use the cvmeas function to obtain the measurement in the order of [azimuth;elevation;range;range-rate].

car_state5 = [1000;0;1000;30;0;0]; % [x;vx;y;vy;z;vz].
measurement5 = cvmeas(car_state5,mp5);
meas_az5 = measurement5(1)
meas_az5 = -14.6825
meas_el5 = measurement5(2)
meas_el5 = 12.4704
meas_rng5 = measurement5(3)
meas_rng5 = 5.7446e 03
meas_rr5 = measurement5(4)
meas_rr5 = -126.2063

the elevation angle is defined as an angle from the xy-plane to the z direction. that is why the elevation angle is positive for a target on the ground relative to the uav. this convention is used throughout the toolbox.

the measurement noise for azimuth, elevation, range, and range-rate is [1,1,20,2], respectively. also, the index of the radar is 2, and the radar can classify the detected object as 1 for the type of 'car'.

index5 = 2; 
covariance5 = diag([1;1;20;2]);
classid5 = 1;

create an objectdetection object for the detection.

time5 = 0;
detection = objectdetection(time5,measurement5,'sensorindex',index5,...
            'measurementnoise',covariance5,'objectclassid',classid5,'measurementparameters',mp5)
detection = 
  objectdetection with properties:
                     time: 0
              measurement: [4x1 double]
         measurementnoise: [4x4 double]
              sensorindex: 2
            objectclassid: 1
    objectclassparameters: []
    measurementparameters: [1x1 struct]
         objectattributes: {}

example 6: classified detections

consider a vision tracking scenario where camera frames feed into an object detector. in such cases, detections often provide a classification of the object. consider an object detector that output bounding box detections and classifies objects into the following classes {'car', 'pedestrian', 'bicycle'}. the statistics of the detector are captured by its confusion matrix c. create a detection with bounding box measurement, 'pedestrian' classification, and confusion matrix c as defined below.

c = [0.9 0.05 0.05; ...
     0.05 0.9 0.05; ...
     0.05 0.05 0.9];
classid = 2; % pedestrian
classparams = struct('confusionmatrix', c);
boundingbox = [250 140 300 400]; % bounding box in top left width height coordinates
detection = objectdetection(0, boundingbox, objectclassid=classid, objectclassparameters=struct('confusionmatrix', c))
detection = 
  objectdetection with properties:
                     time: 0
              measurement: [250 140 300 400]
         measurementnoise: [4x4 double]
              sensorindex: 1
            objectclassid: 2
    objectclassparameters: [1x1 struct]
    measurementparameters: {}
         objectattributes: {}

see also

网站地图