Created
October 1, 2020 13:29
-
-
Save pythonlessons/cd3528657bc2c803e55f3282877a17ff to your computer and use it in GitHub Desktop.
YOLO_aimbot_main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while True: | |
| t1 = time.time() | |
| img = np.array(sct.grab({"top": y-30, "left": x, "width": w, "height": h, "mon": -1})) | |
| img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB) | |
| image, detection_list, bboxes = detect_enemy(yolo, np.copy(img), input_size=YOLO_INPUT_SIZE, CLASSES=TRAIN_CLASSES, rectangle_colors=(255,0,0)) | |
| cv2.circle(image,(int(w/2),int(h/2)), 3, (255,255,255), -1) # center of weapon sight | |
| th_list, t_list = [], [] | |
| for detection in detection_list: | |
| diff_x = (int(w/2) - int(detection[1]))*-1 | |
| diff_y = (int(h/2) - int(detection[2]))*-1 | |
| if detection[0] == "th": | |
| th_list += [diff_x, diff_y] | |
| elif detection[0] == "t": | |
| t_list += [diff_x, diff_y] | |
| if len(th_list)>0: | |
| new = min(th_list[::2], key=abs) | |
| index = th_list.index(new) | |
| pyautogui.move(th_list[index], th_list[index+1]) | |
| if abs(th_list[index])<12: | |
| pyautogui.click() | |
| elif len(t_list)>0: | |
| new = min(t_list[::2], key=abs) | |
| index = t_list.index(new) | |
| pyautogui.move(t_list[index], t_list[index+1]) | |
| if abs(t_list[index])<12: | |
| pyautogui.click() | |
| t2 = time.time() | |
| times.append(t2-t1) | |
| times = times[-50:] | |
| ms = sum(times)/len(times)*1000 | |
| fps = 1000 / ms | |
| print("FPS", fps) | |
| image = cv2.putText(image, "Time: {:.1f}FPS".format(fps), (0, 30), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 2) | |
| #cv2.imshow("OpenCV/Numpy normal", image) | |
| #if cv2.waitKey(25) & 0xFF == ord("q"): | |
| #cv2.destroyAllWindows() | |
| #break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment