Skip to main content
. 2022 May 26;22(11):4040. doi: 10.3390/s22114040
Algorithm 2 Patch-Based Approach.

Inputs:

dataset ← collection of MIMs with the first frame of each MIM

ROImatrix[left_top:[x_coordinate,y_coordinate],right_bottom:[x_coordinate,y_coordinate]]

n,m ← the numbers of rows and columns that are used to divide ROI into n×m regions.

trajectory ← CSV file, each row represents orderofframe(ft),pedestrianno.,pixelxcoordinate,pixelycoordinate

ground_truth ← CSV file, each row represents orderofciorMIM,behaviorofpedestrian1,behaviorofpedestrian2,, behavioroflastpedestrian

Outputs:

pushing_folder, non-pushing_folder

1:regionmatrix[[]]

▹ Automatic patches labeling

2: patch_width(ROI[1,0]ROI[0,0])/m

3: patch_height(ROI[1,1]ROI[0,1])/n

4: for i0,1,,n1 do

5:    for j0,1,,m1 do

6:        region.append([ROI[0,0]+j×patch_width,ROI[0,1]+i×patch_height,ROI[0,0]+(j+1)×patch_width,ROI[0,1]+(i+1)×patch_height])

7:    end for

8: end for

9: patch_width(ROI[1,0]ROI[0,0])/(m1)

10: patch_height(ROI[1,1]ROI[0,1])/(n1)

11: for i0,1,,n2 do

12:    for j0,1,,m2 do

13:        region.append([ROI[0,0]+j×patch_width,ROI[0,1]+i×patch_height,ROI[0,0]+(j+1)×patch_width,ROI[0,1]+(i+1)×patch_height])

14:    end for

15: end for

16: fileCSVfile

17: for each MIMdataset do

18:    frame_orderMIMname

19:    pedFilter(trajectory.frame_order)[1]

20:    patch_no1

21:    for each patch_regionregion do

22:        behavior1 //non-pushing

23:        for each pedpatch_region do

24:           if Filter(ground_truth.frame_order&ped)==2 then

25:               behavior2 //pushing

26:               break

27:           end if

28:        end for

29:        record[patch_no,frame_order,behavior]

30:        file.write(record)

31:        patch_nopatch_no+1

32:    end for

33: end for

▹ Visualization

34: for each framedataset do

35:    frame_orderframename

36:    pedFilter(trajectory.frame_order)[1]

37:    for each personped do

38:        behaviorFilter(ground_truth.frame_order&person)

39:        if behavior ==2 then

40:           draw a circle around the position person[2],person[3]] of pedestrian person[1] over frame

41:        end if

42:    end for

43:    for patch_no1,2,,len(region) do

44:        if Filter(file.frame_order&patch_no)[2]==2 then

45:           draw a red rectangle around region[patch_no1] over frame

46:        else

47:           draw a green rectangle around region[patch_no1] over frame

48:        end if

49:    end for

50: end for

▹ Manual revision

51: for each framedataset do

52:    for each patch_regionregion do

53:        manual revision of patch_region in frame

54:        if patch_regioncontainsonlyapartofonepushingbehavioranditslabelis2 then

55:           manually updating the label of the patch_region in file to 6, where 6 means unknown patch

56:        end if

57:    end for

58: end for

▹ Patch-based MIM dataset creation

59: for each MIMdataset do

60:    MIM_orderMIMname

61:    for patch_no1,2,,len(region) do

62:        patchMIM[region[patch_no1,1]:region[patch_no1,3],[region[patch_no1,0]:region[patch_no1,2]]

63:        if Filter(file.MIM_order&patch_no)[2]==2 then

64:           save patch to pushing_folder under name “MIM_orderpatch_no"

65:        else if Filter(file.MIM_order&patch_no)[2]==1 then

66:           save patch to non-pushing_folder under name “MIM_orderpatch_no"

67:        end if

68:    end for

69: end for