Skip to contents

Given a list containing vectors corresponding to the various variable of tracking data the function returns a list of data frames corresponding to the data for each tracklet based on tracklets identity.

Usage

convert2Tracklets(trackDatList, by = "identity")

Arguments

trackDatList

A list of vector corresponding to the variable characterizing the tracking data.

by

A character vector identifying the tracklets to join by (default = 'identity').

Value

An object of class "tracklets" containing a list of tracklets with tracking informations.

See also

Author

Quentin PETITJEAN

Examples


set.seed(2023)
# generate some dummy tracklets
## start to specify some parameters to generate tracklets
TrackN <- 3 # the number of tracklet to simulate
TrackL <-
  1:1000 # the length of the tracklets or a sequence to randomly sample tracklet length
id <- 0
TrackList <- MoveR::trackletsClass(stats::setNames(lapply(lapply(seq(TrackN), function(i)
  trajr::TrajGenerate(sample(TrackL, 1), random = TRUE, fps = 1)), function(j) {
    id <<- id + 1
    data.frame(
      x.pos = j$x - min(j$x),
      y.pos = j$y - min(j$y),
      frame = j$time,
     identity = paste("Tracklet", id, sep = "_")
    )
  }), seq(TrackN)))

 # convert the list of tracklets to a simple list of variables
 trackDatList <- MoveR::convert2List(TrackList)
 str(trackDatList)
#> List of 5
#>  $ x.pos     : num [1:1738] 15.3 17.5 19.5 20.6 21.9 ...
#>  $ y.pos     : num [1:1738] 7.13 6.64 5.92 4.52 3.17 ...
#>  $ frame     : num [1:1738] 0 1 2 3 4 5 6 7 8 9 ...
#>  $ identity  : chr [1:1738] "Tracklet_1" "Tracklet_1" "Tracklet_1" "Tracklet_1" ...
#>  $ trackletId: chr [1:1738] "1" "1" "1" "1" ...
#>  - attr(*, "class")= chr "varList"
 
 # convert back the list of variables to a list of tracklet based on tracklets identity
 trackDat <- MoveR::convert2Tracklets(trackDatList, by = "trackletId")
 str(trackDat) # display only the three first elements (dataframes) of the list
#> List of 3
#>  $ 1:'data.frame':	886 obs. of  5 variables:
#>   ..$ x.pos     : num [1:886] 15.3 17.5 19.5 20.6 21.9 ...
#>   ..$ y.pos     : num [1:886] 7.13 6.64 5.92 4.52 3.17 ...
#>   ..$ frame     : num [1:886] 0 1 2 3 4 5 6 7 8 9 ...
#>   ..$ identity  : chr [1:886] "Tracklet_1" "Tracklet_1" "Tracklet_1" "Tracklet_1" ...
#>   ..$ trackletId: chr [1:886] "1" "1" "1" "1" ...
#>  $ 2:'data.frame':	280 obs. of  5 variables:
#>   ..$ x.pos     : num [1:280] 129 131 133 135 136 ...
#>   ..$ y.pos     : num [1:280] 106 106 107 108 109 ...
#>   ..$ frame     : num [1:280] 0 1 2 3 4 5 6 7 8 9 ...
#>   ..$ identity  : chr [1:280] "Tracklet_2" "Tracklet_2" "Tracklet_2" "Tracklet_2" ...
#>   ..$ trackletId: chr [1:280] "2" "2" "2" "2" ...
#>  $ 3:'data.frame':	572 obs. of  5 variables:
#>   ..$ x.pos     : num [1:572] 88.5 90.1 92 93.8 95.1 ...
#>   ..$ y.pos     : num [1:572] 35.5 34.5 33.7 32.8 31.7 ...
#>   ..$ frame     : num [1:572] 0 1 2 3 4 5 6 7 8 9 ...
#>   ..$ identity  : chr [1:572] "Tracklet_3" "Tracklet_3" "Tracklet_3" "Tracklet_3" ...
#>   ..$ trackletId: chr [1:572] "3" "3" "3" "3" ...
#>  - attr(*, "class")= chr "tracklets"