最后一个坐标值返回零

时间:2012-10-08 06:10:02

标签: python list

当假设返回坐标[]的先前值时,last_coordinate []值返回零。它通过摄像机实时读取数据,该摄像机告诉检测到的物体的坐标。我实现last_coordinates的原因是为了比较先前的坐标值和新的坐标值来区分它们并执行一个动作。我该如何解决这个问题?

    import socket
    import os,sys
    import time
    from threading import Thread

    HOST = '59.191.193.67'
    PORT = 5555

    coordinates = []

    def connect():   
        globals()['client_socket'] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client_socket.connect((HOST,PORT))

    def update_coordinates():
        screen_width = 0
        screen_height = 0
        global last_coordinates
        last_coordinates = [0 for _ in range(19)]
        while True:
            try:
                client_socket.send("loc\n")
                data = client_socket.recv(8192)
            except:
                connect();
                continue;

            globals()['coordinates'] = data.split()
            if(not(coordinates[-1] == "eom" and coordinates[0] == "start")):
                continue

            if (screen_width != int(coordinates[2])):
                    screen_width = int(coordinates[2])
                    screen_height = int(coordinates[3])
                    return

            if (coordinates != last_coordinates):
                 return last_coordinates[16:19]
            last_coordinates = coordinates[:]



Thread(target=update_coordinates).start()

0 个答案:

没有答案