import cv2
import numpy as np
import pyautogui
import time
import keyboard
def capture_screen():
screen = [Link]()
frame = [Link](screen)
frame = [Link](frame,
cv2.COLOR_BGR2RGB)
return frame
def detect_heads(frame):
hsv = [Link](frame,
cv2.COLOR_BGR2HSV)
# Define the color range for red
(in HSV)
lower_color = [Link]([0, 100,
100]) # Lower bound for red
upper_color = [Link]([10, 255,
255]) # Upper bound for red
lower_color2 = [Link]([160,
100, 100]) # Lower bound for red
(for the other end of the spectrum)
upper_color2 = [Link]([180,
255, 255]) # Upper bound for red
(for the other end of the spectrum)
mask1 = [Link](hsv,
lower_color, upper_color)
mask2 = [Link](hsv,
lower_color2, upper_color2)
mask = mask1 | mask2 #
Combine both masks for full red
coverage
contours, _ =
[Link](mask,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
heads = []
for contour in contours:
if [Link](contour) >
100:
x, y, w, h =
[Link](contour)
center_x = x + w // 2
center_y = y + h // 2
[Link]((center_x,
center_y))
return heads
def aim_at(head):
target_x, target_y = head
[Link](target_x,
target_y)
def main():
aiming = False
while True:
if keyboard.is_pressed('a'):
aiming = not aiming
[Link](0.5)
if aiming:
frame = capture_screen()
heads =
detect_heads(frame)
if heads:
aim_at(heads[0])
for head in heads:
[Link](frame, head, 5,
(0, 255, 0), -1)
[Link]("Detected
Heads", frame)
if [Link](1) & 0xFF ==
ord('q'):
break
[Link](0.01)
[Link]()
if __name__ == "__main__":
main()