Skip to main content
. 2023 Aug 15;9(8):161. doi: 10.3390/jimaging9080161
Algorithm 1: Collision avoidance and feedback
  • 1.

    Capture video from the camera

  • 2.

    fori=0,1,,N, N=NUMBER OF BOUNDING BOXES IN ONE FRAMEdo

  • 3.
    Store the center point, height, and width of the bounding box in the current frame, and the object trajectory vectors
    1. [xIc(ti),yIc(ti)]=[xI(ti)+wI(ti)2,yI(ti)+hI(ti)2]
    2. a=xIc(ti+1)xIc(ti)
    3. b=yIc(ti+1)yIc(ti)
  • 4.
    Check if the object is moving toward the user:
    • a.
      IfwI(t+1i)×hI(t+1i)>wI(ti)×hI(ti)then
      1. IfxIc(ti)<wimg3ANDb<0
        print “Name of the detected object” is approaching you from your left side!
      2. elseIfwimg3<xIc(ti)<2wimg3ANDb<0
        print “Name of the detected object” is in front of you!
      3. elseIf2wimg3<xIc(ti)ANDa<0ANDb<0
        print “Name of the detected object” is approaching you from your right side!
    • b.
      IfwI(t+1i)×hI(t+1i)=wI(ti)×hI(ti)then
      print “Object is static!”
    • c.
      end
  • 5.

    Store the current center points and distance for the next iteration

    [xIc(ti),yIc(ti)]=[xIc(t+1i),yIc(t+1i)]

  • 6.

    end