RFID 閘門與人類方向偵測系統。該系統是一個具有人類方向偵測功能的 RFID 閘門系統。系統使用 Spring Boot 作為主伺服器,通過純 Socket 與 RFID 閱讀器連接,並利用 FastAPI 的 WebSocket 進行 YOLO 偵測。系統能夠使用 YOLO 偵測人類的移動方向,並相應地記錄物品的訪問方向。
tracks = tracker.update_tracks(detections, frame=frame)
current_ids = set()
for track in tracks:
if not track.is_confirmed() or track.time_since_update > 1:
continue
track_id = track.track_id
current_ids.add(track_id)
bbox = track.to_tlbr()
x1, y1, x2, y2 = map(int, bbox) # Human Box Coordinate
object_center = ((x1 + x2) // 2, (y1 + y2) // 2)
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(frame, f"ID: {track_id}", (x1, y1 - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
if track_id not in movement_states: # Cannot just calculate the movement with 'perfect' in and exist axis
if object_center[0] < frame_width // 3:
movement_states[track_id] = {
'start': 'left', 'end': None, 'detected': True, 'direction': None, 'enterTime': datetime.now(timezone.utc)}
elif object_center[0] > frame_width * 2 // 3:
movement_states[track_id] = {
'start': 'right', 'end': None, 'detected': True, 'direction': None, 'enterTime': datetime.now(timezone.utc)}
else:
movement_states[track_id] = {
'start': 'middle', 'end': None, 'detected': True, 'direction': None, 'enterTime': datetime.now(timezone.utc)}
state = movement_states[track_id]
if object_center[0] > frame_width * 2 // 3:
state['end'] = 'right'
state['direction'] = 'right'
elif object_center[0] < frame_width // 3:
state['end'] = 'left'
state['direction'] = 'left'
state['detected'] = True
for track_id in list(movement_states.keys()):
state = movement_states[track_id]
if track_id not in current_ids:
state['detected'] = False
if has_disappeared(track_id, movement_states):
enter_time = state['enterTime']
exit_time = datetime.now(timezone.utc)
# Check if starting from left and need to leave from right
if state['start'] == 'left' and state['end'] == 'right':
print(f"Person {track_id} moved from Left to Right")
asyncio.run(send_movement_data(
uri_for_movement, "right", enter_time, exit_time))
elif state['start'] == 'right' and state['end'] == 'left':
print(f"Person {track_id} moved from Right to Left")
asyncio.run(send_movement_data(
uri_for_movement, "left", enter_time, exit_time))
del movement_states[track_id]