protected Term assembleTrackSegment(
     long frameNumber1,
     long x1,
     long y1,
     long frameNumber2,
     long x2,
     long y2,
     TrackSegment trackSegment) {
   Term prologFrame1 = new PrologInteger(frameNumber1);
   Term prologX1 = new PrologInteger(x1);
   Term prologY1 = new PrologInteger(y1);
   Term prologFrame2 = new PrologInteger(frameNumber2);
   Term prologX2 = new PrologInteger(x2);
   Term prologY2 = new PrologInteger(y2);
   Term list3 = formTrackOfBlob(trackSegment);
   Term prologMeanBlobArea = new PrologReal(trackSegment.meanBlobArea);
   Term prologMeanForegroundArea = new PrologReal(trackSegment.meanForegroundArea);
   Term prologMeanCharacteristicLength = new PrologReal(trackSegment.meanCharacteristicLength);
   Term prologMeanSquaredCharacteristicLength =
       new PrologReal(trackSegment.meanSquaredCharacteristicLength);
   Term prologMeanStandardizedArea = new PrologReal(trackSegment.meanStandardizedArea);
   Term prologMeanContourLength = new PrologReal(trackSegment.meanContourLength);
   Term prologWR2Mean = new PrologReal(trackSegment.getWindowedR2Mean());
   Term prologWR2StandardDeviation = new PrologReal(trackSegment.getWindowedR2StandardDeviation());
   Term prologWR2Skewness = new PrologReal(trackSegment.getWindowedR2Skewness());
   Term prologWR2Kurtosis = new PrologReal(trackSegment.getWindowedR2Kurtosis());
   Term prologWR2Cardinality = new PrologInteger(trackSegment.getWindowedR2Cardinality());
   Term prologMeanVelocity = new PrologReal(trackSegment.meanVelocity);
   Term prologTrackSegment =
       new PrologSet(
           -SymbolCodes.symbolCode_E_frame1,
           prologFrame1,
           new PrologSet(
               -SymbolCodes.symbolCode_E_x1,
               prologX1,
               new PrologSet(
                   -SymbolCodes.symbolCode_E_y1,
                   prologY1,
                   new PrologSet(
                       -SymbolCodes.symbolCode_E_frame2,
                       prologFrame2,
                       new PrologSet(
                           -SymbolCodes.symbolCode_E_x2,
                           prologX2,
                           new PrologSet(
                               -SymbolCodes.symbolCode_E_y2,
                               prologY2,
                               new PrologSet(
                                   -SymbolCodes.symbolCode_E_coordinates,
                                   list3,
                                   new PrologSet(
                                       -SymbolCodes.symbolCode_E_mean_blob_area,
                                       prologMeanBlobArea,
                                       new PrologSet(
                                           -SymbolCodes.symbolCode_E_mean_foreground_area,
                                           prologMeanForegroundArea,
                                           new PrologSet(
                                               -SymbolCodes
                                                   .symbolCode_E_mean_characteristic_length,
                                               prologMeanCharacteristicLength,
                                               new PrologSet(
                                                   -SymbolCodes
                                                       .symbolCode_E_mean_squared_characteristic_length,
                                                   prologMeanSquaredCharacteristicLength,
                                                   new PrologSet(
                                                       -SymbolCodes
                                                           .symbolCode_E_mean_standardized_area,
                                                       prologMeanStandardizedArea,
                                                       new PrologSet(
                                                           -SymbolCodes
                                                               .symbolCode_E_mean_contour_length,
                                                           prologMeanContourLength,
                                                           new PrologSet(
                                                               -SymbolCodes.symbolCode_E_wr2_mean,
                                                               prologWR2Mean,
                                                               new PrologSet(
                                                                   -SymbolCodes
                                                                       .symbolCode_E_wr2_standard_deviation,
                                                                   prologWR2StandardDeviation,
                                                                   new PrologSet(
                                                                       -SymbolCodes
                                                                           .symbolCode_E_wr2_skewness,
                                                                       prologWR2Skewness,
                                                                       new PrologSet(
                                                                           -SymbolCodes
                                                                               .symbolCode_E_wr2_kurtosis,
                                                                           prologWR2Kurtosis,
                                                                           new PrologSet(
                                                                               -SymbolCodes
                                                                                   .symbolCode_E_wr2_cardinality,
                                                                               prologWR2Cardinality,
                                                                               new PrologSet(
                                                                                   -SymbolCodes
                                                                                       .symbolCode_E_mean_velocity,
                                                                                   prologMeanVelocity,
                                                                                   PrologEmptySet
                                                                                       .instance)))))))))))))))))));
   return prologTrackSegment;
 }
 protected Term formTrackOfBlob(TrackSegment segment) {
   long beginningTime = segment.beginningTime;
   int[][] rectangles = segment.rectangles;
   double[] windowedR2ReferentValues = segment.getWindowedR2ReferentValues();
   Term list3 = PrologEmptyList.instance;
   for (int n = rectangles.length - 1; n >= 0; n--) {
     int[] currentRectangle = rectangles[n];
     long currentForegroundArea = segment.foregroundAreaValues[n];
     double currentCharacteristicLength = segment.characteristicLengthValues[n];
     long currentContourLength = segment.contourLengthValues[n];
     double currentR2 = windowedR2ReferentValues[n];
     double currentVelocity = segment.velocityValues[n];
     Term prologFrameN = new PrologInteger(beginningTime + currentRectangle[0]);
     Term prologXn =
         new PrologInteger(StrictMath.round((currentRectangle[1] + currentRectangle[2]) / 2.0));
     Term prologYn =
         new PrologInteger(StrictMath.round((currentRectangle[3] + currentRectangle[4]) / 2.0));
     Term prologWidthN = new PrologInteger(currentRectangle[2] - currentRectangle[1]);
     Term prologHeightN = new PrologInteger(currentRectangle[4] - currentRectangle[3]);
     Term prologForegroundAreaN = new PrologInteger(currentForegroundArea);
     Term prologCharacteristicLengthN = new PrologReal(currentCharacteristicLength);
     Term prologContourLengthN = new PrologInteger(currentContourLength);
     Term prologR2N = new PrologReal(currentR2);
     Term prologVelocityN = new PrologReal(currentVelocity);
     Term prologRectangle =
         new PrologSet(
             -SymbolCodes.symbolCode_E_frame,
             prologFrameN,
             new PrologSet(
                 -SymbolCodes.symbolCode_E_x,
                 prologXn,
                 new PrologSet(
                     -SymbolCodes.symbolCode_E_y,
                     prologYn,
                     new PrologSet(
                         -SymbolCodes.symbolCode_E_width,
                         prologWidthN,
                         new PrologSet(
                             -SymbolCodes.symbolCode_E_height,
                             prologHeightN,
                             new PrologSet(
                                 -SymbolCodes.symbolCode_E_foreground_area,
                                 prologForegroundAreaN,
                                 new PrologSet(
                                     -SymbolCodes.symbolCode_E_characteristic_length,
                                     prologCharacteristicLengthN,
                                     new PrologSet(
                                         -SymbolCodes.symbolCode_E_contour_length,
                                         prologContourLengthN,
                                         new PrologSet(
                                             -SymbolCodes.symbolCode_E_r2,
                                             prologR2N,
                                             new PrologSet(
                                                 -SymbolCodes.symbolCode_E_velocity,
                                                 prologVelocityN,
                                                 PrologEmptySet.instance))))))))));
     list3 = new PrologList(prologRectangle, list3);
   }
   ;
   return list3;
 }