当假定返回坐标[] 的先前值时,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()