# RedisCache0
# İnsan takip sistemi
import random
import cv2
from cvzone.PoseModule import PoseDetector
detector = PoseDetector()
x = 1280
y = 720
distanceVar = 1210
font = cv2.FONT_HERSHEY_SIMPLEX
org = (50, 50)
fontScale = 2
fontScale2 = 1
color = (255, 0, 0)
color2 = (255, 255, 255)
thickness = 2
areaOne = ((0, int(x/2)), (0, int(y/2)), "1")
areaTwo = ((int(x/2), x), (0, int(y/2)), "2")
areaThree = ((0, int(x/2)), (int(y/2), y), "3")
areaFour = ((int(x/2), x), (int(y/2), y), "4")
areaNow = "Bekleniyor..."
print(areaThree)
# cap = cv2.VideoCapture("peoples.mp4")
# cap.set(cv2.CAP_PROP_FRAME_WIDTH, x)
# cap.set(cv2.CAP_PROP_FRAME_HEIGHT, y)
def writeUniqeID(img, bbox, id):
coordsX, coordsY = bbox["bbox"][0]+20, bbox["bbox"][1]+20
cv2.putText(img, f"ID: {id}", (coordsX, coordsY), font,
fontScale2, color2, 2, cv2.LINE_AA)
inScreen = False
def generateUID():
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
chars = list(chars.strip())
generatedChars = []
for i in range(10):
generatedChars.append(random.choice(chars))
return "".join(generatedChars)
img = cv2.imread("human.jpg")
img = detector.findPose(img)
lmList, bbox = detector.findPosition(img, bboxWithHands=False)
if bbox != {} and inScreen is False:
uniqueID = generateUID()
inScreen = True
print(inScreen)
if bbox == {}:
inScreen = False
try:
if bbox != {}:
writeUniqeID(img, bbox, uniqueID)
img = cv2.line(img, (int(x/2), 0), (int(x/2), y), (0, 255, 0), 3)
img = cv2.line(img, (0, int(y/2)), (x, int(y/2)), (0, 255, 0), 3)
except Exception as e:
print(e)
# print(bbox)
if bbox:
# centerCords = (int((bbox["bbox"][1] + bbox["bbox"][3]) / 2), int((bbox["bbox"][0] + bbox["bbox"][2]) / 2))
img = cv2.circle(img, bbox["center"], radius=5, color=(255, 255, 255), thickness=-1)
img = cv2.line(img, bbox["center"], (int(x/2), int(y/2)), color=(0, 0, 255), thickness=3)
print(bbox)
centerX = bbox["center"][0]
centerY = bbox["center"][1]
print(1210 / (bbox["center"][1] - bbox["bbox"][1]) * 2)
estDistance = "%.2f" % float(1210 / (bbox["center"][1] - bbox["bbox"][1]) * 2)
coordsX, coordsY = bbox["bbox"][0] + 40, bbox["bbox"][1] + 20
print(bbox)
cv2.putText(img, f"Tahmini Uzaklik: {estDistance} metre", (coordsX, coordsY), font,
fontScale2, (0, 0, 0), 2, cv2.LINE_AA)
print(f"Tahmini Uzaklik: {estDistance} metre")
# print(centerX in range(areaThree[0][0], areaThree[0][1]), centerY in range(areaOne[1][0], areaOne[1][0]))
if centerX in range(areaOne[0][0], areaOne[0][1]) and centerY in range(areaOne[1][0], areaOne[1][1]):
areaNow = f"{areaOne[2]}. Bolge"
elif centerX in range(areaTwo[0][0], areaTwo[0][1]) and centerY in range(areaTwo[1][0], areaTwo[1][1]):
areaNow = f"{areaTwo[2]}. Bolge"
elif centerX in range(areaThree[0][0], areaThree[0][1]) and centerY in range(areaThree[1][0], areaThree[1][1]):
areaNow = f"{areaThree[2]}. Bolge"
elif centerX in range(areaFour[0][0], areaFour[0][1]) and centerY in range(areaFour[1][0], areaFour[1][1]):
areaNow = f"{areaFour[2]}. Bolge"
# print(areaNow)
img = cv2.putText(img, areaNow, org, font,
fontScale, color, thickness, cv2.LINE_AA)
while 1:
cv2.imshow("Image", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# cap.release()
cv2.destroyAllWindows()