-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (43 loc) · 1.54 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import cvzone
import cv2
import os
import cvzone
import cv2
from cvzone.PoseModule import PoseDetector
cap = cv2.VideoCapture(0)
detector = PoseDetector()
shirtFolderPath = "Resources/Shirts"
listShirts = os.listdir(shirtFolderPath)
# print(listShirts)
fixedRatio = 262 / 190 # widthOfShirt/widthOfPoint11to12
shirtRatioHeightWidth = 581 / 440
imageNumber = 0
imgButtonRight = cv2.imread("Resources/button.png", cv2.IMREAD_UNCHANGED)
imgButtonLeft = cv2.flip(imgButtonRight, 1)
counterRight = 0
counterLeft = 0
selectionSpeed = 10
while True:
success, img = cap.read()
img = detector.findPose(img)
# img = cv2.flip(img,1)
lmList, bboxInfo = detector.findPosition(img, bboxWithHands=False, draw=False)
if lmList:
# center = bboxInfo["center"]
lm11 = lmList[11][1:3]
lm12 = lmList[12][1:3]
imgShirt = cv2.imread(os.path.join(shirtFolderPath, listShirts[imageNumber]), cv2.IMREAD_UNCHANGED)
widthOfShirt = int((lm11[0] - lm12[0]) * fixedRatio)
print(widthOfShirt)
try:
imgShirt = cv2.resize(imgShirt, (widthOfShirt, int(widthOfShirt * shirtRatioHeightWidth)))
except cv2.error as e:
print("Error resizing image:", e)
currentScale = (lm11[0] - lm12[0]) / 190
offset = int(44 * currentScale), int(48 * currentScale)
try:
img = cvzone.overlayPNG(img, imgShirt, (lm12[0] - offset[0], lm12[1] - offset[1]))
except:
pass
cv2.imshow("Image", img)
cv2.waitKey(1)