Guest User

fivem

a guest
Mar 28th, 2024
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | Fixit | 0 0
  1. import cv2
  2. import numpy as np
  3. import pyautogui
  4.  
  5. # Function to detect red touching purple within a circular region of interest (ROI)
  6. def detect_red_touching_purple():
  7. # Capture the screen
  8. screenshot = pyautogui.screenshot()
  9. img = cv2.cvtColor(np.array(screenshot), cv2.COLOR_RGB2BGR)
  10.  
  11. # Get the dimensions of the screen
  12. screen_width, screen_height = pyautogui.size()
  13.  
  14. # Define the circular region of interest (ROI) parameters
  15. roi_radius = min(screen_width, screen_height) // 4 # Radius of the circular ROI
  16. roi_center_x = screen_width // 2 # X-coordinate of the center of the ROI
  17. roi_center_y = screen_height // 2 # Y-coordinate of the center of the ROI
  18.  
  19. # Create a mask for the circular ROI
  20. mask = np.zeros((screen_height, screen_width), dtype=np.uint8)
  21. cv2.circle(mask, (roi_center_x, roi_center_y), roi_radius, 255, thickness=cv2.FILLED)
  22.  
  23. # Apply the mask to the original image
  24. masked_img = cv2.bitwise_and(img, img, mask=mask)
  25.  
  26. # Convert BGR to HSV (Hue, Saturation, Value)
  27. hsv = cv2.cvtColor(masked_img, cv2.COLOR_BGR2HSV)
  28.  
  29. # Define range of red color in HSV
  30. lower_red = np.array([0, 100, 100])
  31. upper_red = np.array([10, 255, 255])
  32.  
  33. # Define range of purple color in HSV
  34. lower_purple = np.array([125, 50, 50])
  35. upper_purple = np.array([150, 255, 255])
  36.  
  37. # Threshold the HSV image to get only red and purple colors within the circular ROI
  38. mask_red = cv2.inRange(hsv, lower_red, upper_red)
  39. mask_purple = cv2.inRange(hsv, lower_purple, upper_purple)
  40.  
  41. # Bitwise AND operation to find regions where both red and purple are present within the circular ROI
  42. red_and_purple_touching = cv2.bitwise_and(mask_red, mask_purple)
  43.  
  44. # Check if any nonzero pixel values are present in the resulting image
  45. touching = np.any(red_and_purple_touching)
  46.  
  47. return touching
  48.  
  49. # Main loop
  50. while True:
  51. if detect_red_touching_purple():
  52. # Press the "E" key when red touches purple within the circular ROI
  53. pyautogui.press('e')
  54. print("Red touching purple within the circular ROI. 'E' key pressed.")
  55. else:
  56. print("Red not touching purple within the circular ROI.")
  57.  
  58. # Delay to control the loop rate (adjust as needed)
  59. cv2.waitKey(100)
Advertisement
Add Comment
Please, Sign In to add comment