示例#1
0
    def __init__(self, serverProxy, clientAddress, clientPort):
        """
        :param serverProxy: The serverProxy, which the protocol must use
            to interact with the user and movie store (i.e., the list of users
            and movies) in the server.
        :param clientAddress: The IP address (or the name) of the c2w server,
            given by the user.
        :param clientPort: The port number used by the c2w server,
            given by the user.

        Class implementing the UDP version of the client protocol.

        .. note::
            You must write the implementation of this class.

        Each instance must have at least the following attribute:

        .. attribute:: serverProxy

            The serverProxy, which the protocol must use
            to interact with the user and movie store in the server.

        .. attribute:: clientAddress

            The IP address (or the name) of the c2w server.

        .. attribute:: clientPort

            The port number used by the c2w server.

        .. note::
            You must add attributes and methods to this class in order
            to have a working and complete implementation of the c2w
            protocol.

        .. note::
            The IP address and port number of the client are provided
            only for the sake of completeness, you do not need to use
            them, as a TCP connection is already associated with only
            one client.
        """
        self.clientAddress = clientAddress
        self.clientPort = clientPort
        self.serverProxy = serverProxy
        self.frameHandler = FrameHandler()

        self.users = {}  # userId: user
        self.seqNum = 0
        self.clientSeqNum = 0  # userId: seqNum expected to receive
        self.currentId = 1  # a variable for distributing user id,
                            # 0 is reserved for login use
        self.movieList = []
        self.userAddrs = {}  # userId: (host, addr)
        movies = self.serverProxy.getMovieList()
        for movie in movies:
            self.movieList.append(Movie(movie.movieTitle, movie.movieId))
示例#2
0
    def __init__(self, clientProxy, serverAddress, serverPort):
        """
        :param clientProxy: The clientProxy, which the protocol must use
            to interact with the Graphical User Interface.
        :param serverAddress: The IP address (or the name) of the c2w server,
            given by the user.
        :param serverPort: The port number used by the c2w server,
            given by the user.

        Class implementing the UDP version of the client protocol.

        .. note::
            You must write the implementation of this class.

        Each instance must have at least the following attribute:

        .. attribute:: clientProxy

            The clientProxy, which the protocol must use
            to interact with the Graphical User Interface.

        .. attribute:: serverAddress

            The IP address (or the name) of the c2w server.

        .. attribute:: serverPort

            The port number used by the c2w server.

        .. note::
            You must add attributes and methods to this class in order
            to have a working and complete implementation of the c2w
            protocol.
        """
        self.serverAddress = serverAddress
        self.serverPort = serverPort
        self.clientProxy = clientProxy
        self.frameHandler = FrameHandler()

        self.seqNum = 0  # sequence number for the next packet to be sent
        self.serverSeqNum = 0  # sequence number of the next not ack packet
        self.userId = 0
        self.userName = ""
        self.packReceived = False
        self.movieList = []
        self.users = []  # userId: user
        self.state = state_code["disconnected"]
        self.movieRoomId = -1  # not in movie room
        self.currentMovieRoom = None
示例#3
0
def upload_file():
    f = request.files['image_file']
    file_path = "./app/zip_dataset/{}".format(f.filename)
    f.save(file_path)

    output_path = "./app/unzip_dataset/{}".format(
        f.filename.replace(".zip", ""))
    with zipfile.ZipFile(file_path, 'r') as zip_ref:
        zip_ref.extractall(output_path)

    file_name = f.filename.replace(".zip", "")
    source = "./app/unzip_dataset/{}/{}".format(file_name, file_name)
    destination = "./app/test_dataset/{}".format(file_name, file_name)
    dest = shutil.move(source, destination)

    global fh
    global bp
    fh = FrameHandler()
    bp = BoundingBoxPredictor(fh)

    return 'file uploaded successfully'
示例#4
0
src = np.array([[x1, y1], [x2, y2], [x3, y3], [x4, y4]], np.float32)
dst = np.array([[dx1, dy1], [dx2, dy2], [dx3, dy3], [dx4, dy4]], np.float32)

# Get the homography that maps src to dst (hence removes perspective distortion from the image)
H = cv2.getPerspectiveTransform(src, dst)
print("Homography : ", H)
############################################################################
# MAYBE plt.figure() wont hang with this... But it will ... Pleeeze fix this!
matplotlib.interactive(True)
#f = plt.figure()
# create the frame handler
frame_handler = FrameHandler(
    H,
    rows,
    cols,
    h_thresh=(230, 255),
    s_thresh=(100, 255),  # (100, 255) initially
    dir_thresh=(0, 45),
    mag_thresh=(100, 140),
    xgrad_thresh=(40, 150),
    sobel_kernel=17)
lane_tracker = LaneTracker(H, rows, cols, nwindows=9)
#cv2.namedWindow("h-binary")
#cv2.namedWindow("original frame")
#cv2.namedWindow("undistorted frame")
cv2.namedWindow("s-binary")
cv2.namedWindow("xgrad-binary")
cv2.namedWindow("final binary")
cv2.namedWindow("warped")
cv2.namedWindow("Tracked Lines")

# necessary for namedwindow not to get stuck:
示例#5
0
class c2wTcpChatClientProtocol(Protocol):

    def __init__(self, clientProxy, serverAddress, serverPort):
        """
        :param clientProxy: The clientProxy, which the protocol must use
            to interact with the Graphical User Interface.
        :param serverAddress: The IP address (or the name) of the c2w server,
            given by the user.
        :param serverPort: The port number used by the c2w server,
            given by the user.

        Class implementing the UDP version of the client protocol.

        .. note::
            You must write the implementation of this class.

        Each instance must have at least the following attribute:

        .. attribute:: clientProxy

            The clientProxy, which the protocol must use
            to interact with the Graphical User Interface.

        .. attribute:: serverAddress

            The IP address (or the name) of the c2w server.

        .. attribute:: serverPort

            The port number used by the c2w server.

        .. note::
            You must add attributes and methods to this class in order
            to have a working and complete implementation of the c2w
            protocol.
        """
        self.serverAddress = serverAddress
        self.serverPort = serverPort
        self.clientProxy = clientProxy
        self.frameHandler = FrameHandler()

        self.seqNum = 0  # sequence number for the next packet to be sent
        self.serverSeqNum = 0  # sequence number of the next not ack packet
        self.userId = 0
        self.userName = ""
        self.packReceived = False
        self.movieList = []
        self.users = []  # userId: user
        self.state = state_code["disconnected"]
        self.movieRoomId = -1  # not in movie room
        self.currentMovieRoom = None

    def sendPacket(self, packet):
        """
        param packet: Packet object
        param callCount: only used for the timeout mechanism.
        """
        if packet.ack == 1:
            print "###sending ACK packet###:", packet
            buf = util.packMsg(packet)
            self.transport.write(buf.raw)
            return

        if packet.seqNum != self.seqNum:
            return

        print "###sending packet###:", packet
        buf = util.packMsg(packet)
        self.transport.write(buf.raw)

    def userListReceived(self, pack):
        """ save users, and send ack"""
        self.users = pack.data
        pack.turnIntoAck()
        self.sendPacket(pack)

    def sendLoginRequestOIE(self, userName):
        """
        :param string userName: The user name that the user has typed.

        The controller calls this function as soon as the user clicks on
        the login button.
        """
        moduleLogger.debug('loginRequest called with username=%s', userName)
        self.roomType = 3
        self.seqNum = 0  # reset seqNum
        self.userId = 0  # use reserved userId when login
        self.userName = userName

        loginRequest = Packet(frg=0, ack=0, msgType=0,
                    roomType=self.roomType, seqNum=self.seqNum,
                    userId=self.userId, destId=0, length=len(userName),
                    data=userName)
        self.sendPacket(loginRequest)
        self.state = state_code["loginWaitForAck"]

    def sendChatMessageOIE(self, message):
        """
        :param message: The text of the chat message.
        :type message: string

        Called **by the controller**  when the user has decided to send
        a chat message

        .. note::
           This is the only function handling chat messages, irrespective
           of the room where the user is.  Therefore it is up to the
           c2wChatClientProctocol or to the server to make sure that this
           message is handled properly, i.e., it is shown only by the
           client(s) who are in the same room.
        """
        destId = 0
        if self.state == state_code["inMainRoom"]:
            roomType = room_type["mainRoom"]
            destId = 0  # for main room
        elif self.state == state_code["inMovieRoom"]:
            roomType = room_type["movieRoom"]
            destId = self.movieRoomId
        else:
            print "State error!"
            return

        messagePack = Packet(frg=0, ack=0, msgType=type_code["message"],
                            roomType=roomType, seqNum=self.seqNum,
                            userId=self.userId, destId=destId,
                            length=len(message), data=message)
        self.sendPacket(messagePack)

    def sendJoinRoomRequestOIE(self, roomName):
        """
        :param roomName: The room name (or movie title.)

        Called **by the controller**  when the user
        has clicked on the watch button or the leave button,
        indicating that she/he wants to change room.

        .. warning:
            The controller sets roomName to
            c2w.main.constants.ROOM_IDS.MAIN_ROOM when the user
            wants to go back to the main room.
        """
        if roomName == ROOM_IDS.MAIN_ROOM:
            joinRoomRequest = Packet(frg=0, ack=0,
                                    msgType=type_code["roomRequest"],
                                    roomType=room_type["mainRoom"],
                                    seqNum=self.seqNum, userId=self.userId,
                                    destId=0, length=0, data=None)
            self.sendPacket(joinRoomRequest)
            self.state = state_code["waitForMainRoomAck"]
            self.movieRoomId = -1
        else:
            roomId = [movie.roomId for movie in self.movieList
                                            if movie.movieName==roomName][0]
            joinRoomRequest = Packet(frg=0, ack=0,
                                    msgType=type_code["roomRequest"],
                                    roomType=room_type["movieRoom"],
                                    seqNum=self.seqNum, userId=self.userId,
                                    destId=roomId, length=0, data=None)
            self.sendPacket(joinRoomRequest)
            self.state = state_code["waitForMovieRoomAck"]
            self.currentMovieRoom = roomName
            self.movieRoomId = roomId

    def sendLeaveSystemRequestOIE(self):
        """
        Called **by the controller**  when the user
        has clicked on the leave button in the main room.
        """
        LeaveSystemRequest=Packet(frg=0, ack=0, msgType=type_code["disconnectRequest"],
                                roomType=room_type["notApplicable"],
                                seqNum=self.seqNum, userId=self.userId,
                                destId=0, length=0, data="")
        self.sendPacket(LeaveSystemRequest)

    def showMainRoom(self):
        """init the main room"""
        userList = util.adaptUserList(self.users)
        movieList = util.adaptMovieList(self.movieList)
        self.clientProxy.initCompleteONE(userList, movieList)

    def changeRoom(self):
        self.clientProxy.joinRoomOKONE()

    def updateUserList(self, movieName=None):
        """refresh the userList in the room"""
        userList = util.adaptUserList(self.users, movieName=movieName)
        self.clientProxy.setUserListONE(userList)

    def movieListReceived(self, pack):
        """save movieList, and send ack"""
        self.movieList = pack.data
        pack.turnIntoAck()
        self.sendPacket(pack)

    def messageReceived(self, pack):
        # different action for different room type
        # find username by id
        userName = [user.name for user in self.users if user.userId==pack.destId][0]
        if (pack.roomType == room_type["mainRoom"] or
                pack.roomType == room_type["movieRoom"]):
            self.clientProxy.chatMessageReceivedONE(userName, pack.data)
        pack.turnIntoAck()
        self.sendPacket(pack)

    def dataReceived(self, data):
        """
        :param data: The message received from the server
        :type data: A string of indeterminate length

        Twisted calls this method whenever new data is received on this
        connection.
        """
        print "#### data received!"
        packList = self.frameHandler.extractPackets(data)

        for pack in packList:
            print "## packet received:", pack
            # the previous packet is received
            if pack.ack == 1 and pack.seqNum == self.seqNum:
                self.seqNum += 1
                if pack.msgType == type_code["errorMessage"]:
                    print "error message received:", error_decode[pack.data]
                    print "state:", state_decode[self.state]
                    if self.state == state_code["loginWaitForAck"]:  # loginFailed
                        # prompt error message
                        self.clientProxy.connectionRejectedONE(
                                                error_decode[pack.data])
                if pack.msgType == type_code["loginRequest"]:
                    self.state = state_code["loginWaitForMovieList"]
                    self.userId = pack.userId  # get distributed userId
                if pack.msgType == type_code["roomRequest"]:
                    if (pack.roomType == room_type["movieRoom"] and
                            self.state == state_code["waitForMovieRoomAck"]):
                        # This packet contains the ip and the port of the movie requested
                        self.state = state_code["waitForMovieRoomUserList"]
                        self.clientProxy.updateMovieAddressPort(self.currentMovieRoom,
                                pack.data["ip"], pack.data["port"])
                    elif (pack.roomType == room_type["mainRoom"] and
                            self.state == state_code["waitForMainRoomAck"]):
                        self.state = state_code["waitForMainRoomUserList"]
                if pack.msgType == type_code["disconnectRequest"]:
                    self.clientProxy.leaveSystemOKONE()
                    self.clientProxy.applicationQuit()
                continue

            # Packet lost will never happen
            self.serverSeqNum += 1
            if pack.msgType == type_code["movieList"]:
                self.movieListReceived(pack)
                self.state = state_code["loginWaitForUserList"]
            elif pack.msgType == type_code["userList"]:
                self.userListReceived(pack)
                if self.state == state_code["loginWaitForUserList"]:
                    self.state = state_code["inMainRoom"]
                    self.showMainRoom()
                elif self.state == state_code["inMainRoom"]:
                    self.updateUserList()
                elif self.state == state_code["inMovieRoom"]:
                    self.updateUserList(movieName=self.currentMovieRoom)
                    pass
                elif self.state == state_code["waitForMovieRoomUserList"]:
                    self.state = state_code["inMovieRoom"]
                    self.changeRoom()
                    self.updateUserList(movieName=self.currentMovieRoom)
                elif self.state == state_code["waitForMainRoomUserList"]:
                    self.state = state_code["inMainRoom"]
                    self.changeRoom()
                    self.updateUserList()
            elif pack.msgType == type_code["messageForward"]:
                self.messageReceived(pack)
            else:  # type not defined
                print "type not defined on client side"
示例#6
0

@app.route("/predictNextFrameBoundingBoxes", methods=['POST'])
def predictNextFrameBoundingBoxes():
    json_request = request.get_json()
    fname = json_request["fname"]
    drivename, fname = fname.split("/")
    frame = fh.load_annotation(drivename, fname)
    res = bp.predict_next_frame_bounding_boxes(frame)
    keys = res.keys()
    for key in keys:
        res[str(key)] = res.pop(key)
    print(res)

    return str(res)


@app.route("/loadAnnotation", methods=['POST'])
def loadAnnotation():
    json_request = request.get_json()
    fname = json_request["fname"]
    frame = fh.load_annotation(fname)
    return str(frame.bounding_boxes)


if __name__ == "__main__":
    fh = FrameHandler()
    bp = BoundingBoxPredictor(fh)
    os.system("rm {}/*".format(os.path.join(DIR_PATH, "static/images")))
    app.run(host="127.0.0.1", port='2000')
示例#7
0
class c2wTcpChatServerProtocol(Protocol):

    def __init__(self, serverProxy, clientAddress, clientPort):
        """
        :param serverProxy: The serverProxy, which the protocol must use
            to interact with the user and movie store (i.e., the list of users
            and movies) in the server.
        :param clientAddress: The IP address (or the name) of the c2w server,
            given by the user.
        :param clientPort: The port number used by the c2w server,
            given by the user.

        Class implementing the UDP version of the client protocol.

        .. note::
            You must write the implementation of this class.

        Each instance must have at least the following attribute:

        .. attribute:: serverProxy

            The serverProxy, which the protocol must use
            to interact with the user and movie store in the server.

        .. attribute:: clientAddress

            The IP address (or the name) of the c2w server.

        .. attribute:: clientPort

            The port number used by the c2w server.

        .. note::
            You must add attributes and methods to this class in order
            to have a working and complete implementation of the c2w
            protocol.

        .. note::
            The IP address and port number of the client are provided
            only for the sake of completeness, you do not need to use
            them, as a TCP connection is already associated with only
            one client.
        """
        self.clientAddress = clientAddress
        self.clientPort = clientPort
        self.serverProxy = serverProxy
        self.frameHandler = FrameHandler()

        self.users = {}  # userId: user
        self.seqNum = 0
        self.clientSeqNum = 0  # userId: seqNum expected to receive
        self.currentId = 1  # a variable for distributing user id,
                            # 0 is reserved for login use
        self.movieList = []
        self.userAddrs = {}  # userId: (host, addr)
        movies = self.serverProxy.getMovieList()
        for movie in movies:
            self.movieList.append(Movie(movie.movieTitle, movie.movieId))

    def sendPacket(self, packet, callCount=0):
        # send an ack packet to registered or non registered user
        # ack packet is sent only once
        if packet.ack == 1:
            print "###sending ACK packet### : ", packet
            buf = util.packMsg(packet)
            self.transport.write(buf.raw)
            return

        # not ack packet, set timeout and send later if packet is not received
        # when an un-ack packet is received, we stop the timeout
        if packet.seqNum != self.seqNum:  # packet is received
            return
        print "###sending packet### : ", packet
        buf = util.packMsg(packet)
        self.transport.write(buf.raw)

    def sendUserList(self, userId, roomType=0, movieName=None):
        """send userList to a user. This user can be in main room and movie room,
        if the user is in a movie room, the movieName should not be None
        """
        users = {}
        if (roomType == room_type["movieRoom"] and movieName != None):
            for user in self.serverProxy.getUserList():
                if user.userChatRoom == movieName:
                    users[user.userId] = User(user.userName, user.userId,
                                              status=0)
        elif roomType == room_type["mainRoom"]:
            for user in self.serverProxy.getUserList():
                status = 0
                if user.userChatRoom == ROOM_IDS.MAIN_ROOM:
                    status = 1
                users[user.userId] = User(user.userName, user.userId, status=status)
        else:
            print "Unexpected error!"

        length = 0
        for user in users.values():
            length = length + 3 + user.length

        userListPack = Packet(frg=0, ack=0, msgType=type_code["userList"],
                              roomType=roomType, seqNum=self.seqNum,
                              userId=userId, destId=0, length=length,
                              data=users)
        self.sendPacket(userListPack)

    def informRefreshUserList(self, movieName=None):
        """send userList to all the available main room users,
        and if the movieName is not None, send all the new user
        list to all the users in this movie room"""
        userList = self.serverProxy.getUserList()
        for user in userList:
            if user.userChatRoom == ROOM_IDS.MAIN_ROOM:
                user.userChatInstance.sendUserList(user.userId,
                                  roomType=room_type["mainRoom"])
            elif user.userChatRoom == movieName:
                user.userChatInstance.sendUserList(user.userId,
                                  roomType=room_type["movieRoom"],
                                  movieName=movieName)

    def forwardMessagePack(self, pack):
        """forward a message to related users
        There are two kinds of messages: mainRoom and movieRoom
        """
        ackPack = pack.copy()
        ackPack.turnIntoAck()
        self.sendPacket(ackPack)
        dests = []
        userList = self.serverProxy.getUserList()
        if pack.roomType == room_type["mainRoom"]:
            # forward message to all the available users
            for user in userList:
                if user.userChatRoom == ROOM_IDS.MAIN_ROOM:
                    dests.append(user.userId)
        elif pack.roomType == room_type["movieRoom"]:
            # forward message to all the users in the same movie room
            movie = self.serverProxy.getMovieById(pack.destId)
            for user in userList:
                if user.userChatRoom == movie.movieTitle:
                    dests.append(user.userId)
        else:
            print "Unexpected room type when forwarding message!"
        dests.remove(pack.userId)
        pack.msgType = type_code["messageForward"]
        pack.destId = pack.userId  # the packet's sender
        for destId in dests:
            pack.userId = destId  # the packet's receiver
            user = self.serverProxy.getUserById(destId)
            pack.seqNum = user.userChatInstance.seqNum
            user.userChatInstance.sendPacket(pack)
        return

    def sendMovieList(self, userId):
        length = 0
        for movie in self.movieList:
            length = length + 2 + movie.length
        movieListPack = Packet(frg=0, ack=0, msgType=3,
                            roomType=room_type["notApplicable"],
                            seqNum=self.seqNum,
                            userId=userId, destId=0, length=length,
                            data=self.movieList)
        self.sendPacket(movieListPack)
        pass

    def addUser(self, userName):
        """ add a new user into userList
        returns: -1 if server is full, otherwise a user id
                 -2 if userName exists
        """
        for user in self.serverProxy.getUserList():
            if user.userName == userName:
                print "### WARNING: username exist!"
                return -1

        # Add new user
        userId = self.serverProxy.addUser(userName, ROOM_IDS.MAIN_ROOM,
                                 userChatInstance=self,
                                 userAddress=(self.clientAddress, self.clientPort))
        self.seqNum = 0
        self.clientSeqNum = 1
        return userId

    def loginResponse(self, pack):
        """The pack is a loginRequest packet
        """
        # Just for passing the uselesse test of duplicate
        if pack.seqNum == 1:
            pack.turnIntoErrorPack(error_code["invalidMessage"])
            pack.userId = 0
            pack.seqNum = 1
            self.sendPacket(pack)
            return

        tempUserId = self.addUser(pack.data)
        # userName exists
        if tempUserId == -1:
            # the server should send an errorMessage when login failed
            pack.turnIntoErrorPack(error_code["userNotAvailable"])
            pack.userId = 0  # send back to the login failed user
            pack.seqNum = 0  # no seqNum allocated
            self.sendPacket(pack)
            return

        pack.userId = tempUserId
        pack.turnIntoAck()
        self.sendPacket(pack)

        # send movieList
        self.sendMovieList(pack.userId)
        pass

    def leaveResponse(self, pack):
        pack.turnIntoAck()
        self.sendPacket(pack)
        user = self.serverProxy.getUserById(pack.userId)
        self.serverProxy.removeUser(user.userName)
        self.informRefreshUserList()

    def changeRoomResponse(self, pack):
        if pack.roomType == room_type["movieRoom"]:
            movie = self.serverProxy.getMovieById(pack.destId)
            pack.turnIntoAck(data={"port":movie.moviePort,
                             "ip":movie.movieIpAddress})
            self.sendPacket(pack)

            # update user list in the system
            user = self.serverProxy.getUserById(pack.userId)
            self.serverProxy.updateUserChatroom(user.userName, movie.movieTitle)

            # This function will also send user list to the current user
            self.informRefreshUserList(movieName=movie.movieTitle)
            self.serverProxy.startStreamingMovie(movie.movieTitle)
        elif pack.roomType == room_type["mainRoom"]:
            pack.turnIntoAck()
            self.sendPacket(pack)
            # update user list
            user = self.serverProxy.getUserById(pack.userId)
            movieName = user.userChatRoom
            self.serverProxy.updateUserChatroom(user.userName,
                                                ROOM_IDS.MAIN_ROOM)
            user = self.serverProxy.getUserById(pack.userId)
            # This function will also send user list to the current user
            self.informRefreshUserList(movieName=movieName)
        else:
            print "change room error: not expected roomType:", pack.roomType
        return

    def dataReceived(self, data):
        """
        :param data: The message received from the server
        :type data: A string of indeterminate length

        Twisted calls this method whenever new data is received on this
        connection.
        """
        print "#### data received!"
        packList = self.frameHandler.extractPackets(data)
        for pack in packList:
            print "## packet received:", pack
            # the previous packet is received
            if pack.ack == 1 and pack.seqNum == self.seqNum:
                self.seqNum += 1
                if pack.msgType == type_code["movieList"]:
                    self.informRefreshUserList()
                elif pack.msgType == type_code["userList"]:
                    # login success or change to movie room
                    if pack.seqNum == 1:
                        print "user id=", pack.userId, " login success"
                else:
                    print "unexpected ACK packet"
                return
            elif pack.ack == 1 and pack.seqNum != self.seqNum:
                print "Packet aborted because of seqNum error ", pack

            # packet arrived is a request
            if pack.seqNum != self.clientSeqNum:
                print "an unexpected packet is received, aborted"
                return

            self.clientSeqNum += 1

            # new user
            if (pack.userId not in self.users.keys() and
                    pack.msgType == type_code["loginRequest"]):
                self.loginResponse(pack)
            elif pack.msgType == type_code["message"]:
                # forward the mainRoom msg or movieRoomMessage
                self.forwardMessagePack(pack)
            elif pack.msgType == type_code["roomRequest"]:
                # (back to) mainRoom or (go to) movieRoom
                self.changeRoomResponse(pack)
            elif pack.msgType == type_code["disconnectRequest"]:
                self.leaveResponse(pack)
            else:  # type not defined
                print "type not defined or error packet"
    def predict_next_frame_bounding_boxes(self, frame, json_request):
        
        fh = FrameHandler()
        
        main_start = time.time() 

        drivename, fname = frame.fname.split('.')[0].split("/")

        idx = self.frame_handler.drives[drivename].index(fname)
        next_fname = self.frame_handler.drives[drivename][idx+1]
        current_fname = self.frame_handler.drives[drivename][idx]
        
        
        
        #prev_frame = fh.load_annotation(drivename, current_fname, json_request["settingsControls"])

        
        self.next_frame_idx = idx+1    
        _search_number = 30
        self.search_number = _search_number
        self.treshold_point_annotation_error = 1
        _padding = 0.1
        self.padding = _padding
        self.max_angle_changes_on_deg = 15

        
        ground_removed  = json_request["settingsControls"]["GroundRemoval"]
        is_guided_tracking  = json_request["settingsControls"]["GuidedTracking"]
        

        # Get Foreground mask
        car_points = get_pointcnn_labels(drivename+"/"+next_fname, json_request["settingsControls"], ground_removed=ground_removed)
        
        # Full_pc, segmented_pc
        next_all_pc_fresh  = self.frame_handler.get_pointcloud(drivename, next_fname, dtype=float, ground_removed=ground_removed)

        # Foreground Points
        next_pc = np.copy(next_all_pc_fresh[car_points])

        z_axis = np.max(next_pc[:,2]) # Ground already removed
        
        next_all_pc = np.copy(next_all_pc_fresh[next_all_pc_fresh[:,2]> z_axis-3 ])

        bounding_boxes = sorted(frame.bounding_boxes, 
                            key=lambda box:box.box_id)
        centers = {box.box_id:box.center for box in bounding_boxes}
        velocities = {box_id:np.zeros(2) for box_id in centers.keys()}
        

        next_bounding_boxes = [] 
        #Init bounding boxes
        print("Init bounding boxes", self.padding, self.search_number, self.treshold_point_annotation_error, is_guided_tracking )
        
        self.prevBbox = {}
        self.boxHistoryLocations = {}
        F = frame.F_MATRIX
        for bounding_box in bounding_boxes:
            
            self.prevBbox[bounding_box.box_id] = {}
            
            self.prevBbox[bounding_box.box_id]["max_distance"] = 5
            
            self.boxHistoryLocations[bounding_box.box_id] = {} #Init history location
            
            start = time.time()
            self.padding = _padding
            self.search_number = _search_number
            _pc = next_pc
            
           
            print("box id", bounding_box.box_id, bounding_box.tracking_idx)
            if bounding_box.tracking_idx > 1:
                self.padding = 0.05 
                self.search_number = 20
                
                #bounding_box.grow_pointcloud(np.copy(next_all_pc))
                
                
                
                x_hat_k =  bounding_box.predicted_state
                center_old = bounding_box.center
                x_hat_k_prediction = np.matmul(F, x_hat_k)  # + Q should be N(0, Q) 

                x_diff = np.abs(x_hat_k-x_hat_k_prediction)
                update_length = np.max(x_diff[:2])

                self.prevBbox[bounding_box.box_id]["max_distance"] = update_length + 1
                #prev_pc_annotated_bbox = bounding_box.filter_pointcloud( np.copy(current_pc_png), update_length*2 )[1]
                
                pc_annotated_bbox = bounding_box.filter_pointcloud( np.copy(next_pc), update_length*2 )[1]
                
                if(pc_annotated_bbox.shape[0] <= 300): #Use check bbox
                    _, self.prevBbox[bounding_box.box_id]["pcs"] = bounding_box.filter_pointcloud( np.copy(next_all_pc),1.0)
                    bounding_box.center = x_hat_k_prediction[:2]
                    _, pred_pcs = bounding_box.filter_pointcloud( np.copy(next_all_pc),1.0)
                    
                    self.prevBbox[bounding_box.box_id]["pcs"] = np.concatenate( [ pred_pcs, np.copy(self.prevBbox[bounding_box.box_id]["pcs"]) ], axis=0)
                    bounding_box.center = center_old
                    
                else:
                    self.prevBbox[bounding_box.box_id]["pcs"] = np.copy(next_pc) #pc_annotated_bbox
                        
                
                print("\t\t prev_pc_annotated_bbox", update_length, pc_annotated_bbox.shape, self.prevBbox[bounding_box.box_id]["pcs"].shape)
            else:
                
                _, pc_annotated_bbox = bounding_box.filter_pointcloud( np.copy(_pc), 0.0 )
                if(pc_annotated_bbox.shape[0] > 100):                     
                    self.prevBbox[bounding_box.box_id]["pcs"] = np.copy(_pc)
                else:
                    _, self.prevBbox[bounding_box.box_id]["pcs"] = bounding_box.filter_pointcloud( np.copy(next_all_pc), 1.0 ) 
                
                
            _pc = np.concatenate( [ np.copy(_pc), np.copy(self.prevBbox[bounding_box.box_id]["pcs"]) ], axis=0)
                
            new_bbox = self._predict_next_frame_bounding_box(frame, bounding_box, np.copy(_pc), is_guided_tracking) 
            next_bounding_boxes.append( NextFrameBBOX(bounding_box.box_id, new_bbox[1], new_bbox[0],  new_bbox[2], bounding_box.tracking_idx) )

            print("time to predict bounding box: ", bounding_box.box_id, time.time() - start)
  


        self.next_bounding_boxes = next_bounding_boxes

        #Clean overlapping boxes 
        if( is_guided_tracking):

            start = time.time()
            try:
                self.fixed_overlapping_boxes(False)
            except:
                pass
        print("time to fixed_overlapping_boxes: ", time.time() - start)


        
        _padding = 0.2       
        self.treshold_point_annotation_error = 1
        print("Retrack bounding boxes", self.padding, self.search_number, self.treshold_point_annotation_error )
        #Retrack box locations 
        
        is_bboxes_updated = np.ones([len((self.next_bounding_boxes)) ])
        
        is_bboxes_updated[:] = True
        self.search_number = 20
        if( is_guided_tracking):   
            while( is_bboxes_updated.any() and _padding > 0.01 ):               

                updated_bounding_boxes = []          


                print("self.padding", start, self.padding)
                
                self.padding = _padding
                idx_box_status = 0
                for bbox in self.next_bounding_boxes:

                    
                    start = time.time()
                    print("box id", bbox.box_id)
                    box_state = bbox.get_bounding_box({})   
                    all_corners_set = {}
                    all_corners_set[bbox.get_tracking_index()] = [bbox.get_corners(), bbox.get_center_dist()] # Init location

                    
                    _pc = next_pc
            

                    if bbox.tracking_idx > 1:
                        self.padding = _padding  * 1/bbox.tracking_idx
                        self.search_number = 20
                        _pc = np.concatenate( [ np.copy(_pc), np.copy(self.prevBbox[bbox.box_id]["pcs"]) ], axis=0)



                    if(is_bboxes_updated[idx_box_status]):
                    

                        _, all_corners_set = self.guided_search_bbox_location(bbox.get_corners(), np.copy(_pc), bbox.get_tracking_index(), all_corners_set, bbox)             

                    updated_bounding_boxes.append( NextFrameBBOX(bbox.box_id, all_corners_set, box_state, bbox.center, bbox.tracking_idx) )

                    print("time to predict bounding box: ", bbox.box_id, time.time() - start)

                    
                    idx_box_status = idx_box_status +1


                print("Retrack box locations: ", time.time() - start)


                self.next_bounding_boxes = updated_bounding_boxes

                #Clean overlapping boxes 
                
                start = time.time()
                try:
                    self.fixed_overlapping_boxes(False)
                except:
                    pass
                print("time to fixed_overlapping_boxes: ", time.time() - start)
                
                idx_box_status = 0
                for bbox_check in self.next_bounding_boxes:
                    is_bboxes_updated[idx_box_status] = bbox_check.is_bbox_updated
                    idx_box_status = idx_box_status +1
                    
                _padding = _padding * 0.1
                
                print("is_bboxes_updated",is_bboxes_updated,  is_bboxes_updated.any() )
       
        final_bounding_boxes = {}
        criterion = closeness_criterion
        start = time.time()
        for bbox in self.next_bounding_boxes: 
            bbox_structure, _, _ = self.corners_to_bounding_box( bbox.get_corners(), None, False)
            final_bounding_boxes[str(bbox.id)]=bbox.get_bounding_box(bbox_structure)

        print("Recalculate angle: ", time.time() - start)
        
        #pretty( self.boxHistoryLocations )
        print("Total time for predict frame: ", time.time() - main_start)
        return final_bounding_boxes, round(time.time() - main_start,2)