# import os
# from PIL import Image
# import random
# import cv2
# import numpy as np
#
# shopdir = '/media/lixuan/Data/sku_data/sku110k/sku110k_yolov5_style/images/train'
# handdir = '/home/lixuan/Arduino/hand_detection/hand'
# bank = os.listdir(shopdir)
# hand = os.listdir(handdir)
# for i in range(len(hand)):
# fw = open('/home/lixuan/Arduino/hand_detection/makehands/labels/trainhand_{}.txt'.format(i),'w')
# handlist = []
# handnum = random.randint(1,4)
# try:
# handlist.append(Image.open(os.path.join(handdir,hand[i])))
# except:
# pass
# for j in range(handnum - 1):
# try:
# handlist.append(Image.open(os.path.join(handdir,hand[random.randint(0,len(hand))])))
# except:
# handlist.append(Image.open('/home/lixuan/Arduino/hand_detection/hand/hand.jpg'))
# if handlist == []:
# handlist.append(Image.open('/home/lixuan/Arduino/hand_detection/hand/hand.jpg'))
# img2 = Image.open(os.path.join(shopdir, bank[random.randint(0, len(bank) - 1)]))
# w2, h2 = img2.size
# for img1 in handlist:
# w1,h1 = img1.size
# ratemin = min(w2/w1,h2/h1)
# if ratemin < 20:
# new_w = int(w2 // random.randint(20,25))
# new_rate = w1 / new_w
# new_h = int(h1 // new_rate)
# img1 = img1.resize((new_w, new_h), Image.ANTIALIAS)
# w1 = new_w
# h1 = new_h
# past_x = random.randint(0,w2 - w1)
# past_y = random.randint(0,h2 - h1)
# img2.paste(img1,(past_x,past_y))
# # img2 = np.array(img2)
# x1 = past_x
# y1 = past_y
# x2 = past_x + w1
# y2 = past_y + h1
# x = ((x1 + x2) / 2) / w2
# y = ((y1 + y2) / 2) / h2
# w = w1 / w2
# h = h1 / h2
# fw.write('0 ' + str(x) + ' ' + str(y) + ' ' + str(w) + ' ' + str(h) + '\n')
# # img2 = cv2.rectangle(img2,(x1,y1),(x2,y2),(0,255,255,0),3)
# img2.save('/home/lixuan/Arduino/hand_detection/makehands/images/trainhand_{}.jpg'.format(i))
# # img2 = np.array(img2)
# # img2 = cv2.resize(img2, (w2 // 2, h2 // 2))
# # cv2.imshow('',img2)
# # cv2.waitKey(0)