import cv2 import serial import time ml = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") webcam = cv2.VideoCapture(0) #serial setup ser = serial.Serial('COM3', 9600) # Replace 'COM3' with your serial port time.sleep(2) crosshair_x, crosshair_y = None, None while True: succes, frame = webcam.read() if not succes: print("Goruntu Basarisiz") break frame_height, frame_width = frame.shape[:2] crosshair_x = frame_width // 2 crosshair_y = frame_height // 2 gray_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = ml.detectMultiScale(gray_img) for (x, y, w, h) in faces: cv2.rectangle(frame, (x, y), (x + w, y + h), (123, 4, 5), 3) face_center_x = x + w // 2 face_center_y = y + h // 2 cv2.circle(frame, (face_center_x, face_center_y), 5, (255, 0, 0), -1) faceY = f"{face_center_y}\n" ser.write(faceY.encode('utf-8')) crosshair_size = 10 # Size of the crosshair cv2.line(frame, (crosshair_x - crosshair_size, crosshair_y), (crosshair_x + crosshair_size, crosshair_y), (0, 255, 0), 2) # Horizontal line (Red) cv2.line(frame, (crosshair_x, crosshair_y - crosshair_size), (crosshair_x, crosshair_y + crosshair_size), (0, 255, 0), 2) # Vertical line (Red) cv2.imshow("video", frame) # Break the loop if the 'q' key is pressed if cv2.waitKey(1) & 0xFF == ord('q'): break8 # Release the webcam and close all OpenCV windows webcam.release() cv2.destroyAllWindows()