import json
import time
import numpy as np
from natsort import natsorted
import cv2
import os
import shutil
from pynput import keyboard
def show_img(idx):
if direction == 0:
return
if 0 <= idx < len(json_paths):
try:
print(idx, json_paths[idx])
json_path=json_paths[idx]
with open(json_path, 'r') as f:
datas = json.load(f)
points = datas['shapes'][0]['points']
img_path = json_path.replace('.json', '.jpg')
img = cv2.imread(img_path)
width, height = img.shape[1], img.shape[0]
x1, y1 = int(points[0][0]), int(points[0][1])
x2, y2 = int(points[1][0]), int(points[1][1])
if x1 == x2: # 垂直线
intersections = [(x1, 0), (x1, height)]
elif y1 == y2: # 水平线