-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2a84589
Showing
2 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import cv2 | ||
from mss import mss | ||
import numpy as np | ||
import win32api | ||
import serial | ||
|
||
|
||
fov = int(input("FOV: ")) | ||
|
||
sct = mss() | ||
|
||
|
||
arduino = serial.Serial('COM6', 115200) | ||
|
||
screenshot = sct.monitors[1] | ||
screenshot['left'] = int((screenshot['width'] / 2) - (fov / 2)) | ||
screenshot['top'] = int((screenshot['height'] / 2) - (fov / 2)) | ||
screenshot['width'] = fov | ||
screenshot['height'] = fov | ||
center = fov/2 | ||
|
||
embaixo = np.array([140,111,160]) | ||
emcima = np.array([148,154,194]) | ||
|
||
speed = float(input("SPEED: ")) | ||
print("ARDUINO LOADED") | ||
|
||
def mousemove(x): | ||
if x < 0: | ||
x = x+256 | ||
|
||
pax = [int(x)] | ||
arduino.write(pax) | ||
|
||
|
||
while True: | ||
if win32api.GetAsyncKeyState(0x01) < 0: | ||
|
||
img = np.array(sct.grab(screenshot)) | ||
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) | ||
mask = cv2.inRange(hsv, embaixo,emcima) | ||
kernel = np.ones((3,3), np.uint8) | ||
dilated = cv2.dilate(mask,kernel,iterations= 5) | ||
thresh = cv2.threshold(dilated, 60, 255, cv2.THRESH_BINARY)[1] | ||
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) | ||
if len(contours) != 0: | ||
mouse = cv2.moments(thresh) | ||
pixel = (int(mouse["m10"] / mouse["m00"]), int(mouse["m01"] / mouse["m00"])) | ||
|
||
aimzao = pixel[0] + 2 | ||
|
||
diff_x = int(aimzao - center) | ||
|
||
alvo = diff_x * speed | ||
|
||
mousemove(alvo) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
#include <Mouse.h> | ||
#include <Wire.h> | ||
#include <SPI.h> | ||
#include <usbhub.h> | ||
USB Usb; | ||
USBHub Hub(&Usb); | ||
|
||
byte bf[2]; | ||
|
||
#include <hidboot.h> | ||
|
||
HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb); | ||
|
||
String myString; | ||
int j = 0; | ||
int c = 0; | ||
int e = 0; | ||
int lmb = 0; | ||
int rmb = 0; | ||
int mmb = 0; | ||
int dx; | ||
int dy; | ||
int arr[2]; | ||
int arrv[8]; | ||
|
||
class MouseRptParser : public MouseReportParser | ||
|
||
{ | ||
|
||
protected: | ||
|
||
void OnMouseMove (MOUSEINFO *mi); | ||
|
||
void OnLeftButtonUp (MOUSEINFO *mi); | ||
|
||
void OnLeftButtonDown (MOUSEINFO *mi); | ||
|
||
void OnRightButtonUp (MOUSEINFO *mi); | ||
|
||
void OnRightButtonDown (MOUSEINFO *mi); | ||
|
||
void OnMiddleButtonUp (MOUSEINFO *mi); | ||
|
||
void OnMiddleButtonDown (MOUSEINFO *mi); | ||
|
||
}; | ||
|
||
|
||
void MouseRptParser::OnMouseMove(MOUSEINFO *mi) | ||
|
||
{ | ||
|
||
dx = mi->dX; | ||
|
||
dy = mi->dY; | ||
|
||
}; | ||
|
||
|
||
|
||
|
||
|
||
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi) | ||
|
||
{ | ||
|
||
lmb = 0; | ||
|
||
}; | ||
|
||
|
||
|
||
|
||
|
||
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi) | ||
|
||
{ | ||
|
||
lmb = 1; | ||
|
||
}; | ||
|
||
|
||
|
||
|
||
|
||
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi) | ||
|
||
{ | ||
|
||
rmb = 0; | ||
|
||
}; | ||
|
||
|
||
|
||
|
||
|
||
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi) | ||
|
||
{ | ||
|
||
rmb = 1; | ||
|
||
}; | ||
|
||
|
||
|
||
|
||
|
||
void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi) | ||
|
||
{ | ||
|
||
mmb = 0; | ||
|
||
}; | ||
|
||
|
||
|
||
|
||
|
||
void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi) | ||
|
||
{ | ||
|
||
mmb = 1; | ||
|
||
}; | ||
|
||
MouseRptParser Prs; | ||
|
||
void setup() { | ||
|
||
delay(5000); | ||
Mouse.begin(); | ||
Serial.begin(115200); | ||
Serial.setTimeout(1); | ||
|
||
Usb.Init(); | ||
HidMouse.SetReportParser(0, &Prs); | ||
} | ||
|
||
void loop() { | ||
dx = 0; | ||
|
||
dy = 0; | ||
|
||
|
||
|
||
j = 0; | ||
|
||
c = 0; | ||
|
||
e = 0; | ||
|
||
|
||
|
||
Usb.Task(); | ||
|
||
|
||
|
||
//Clicking | ||
|
||
if (lmb == 0){ | ||
|
||
Mouse.release(MOUSE_LEFT); | ||
|
||
} | ||
|
||
|
||
|
||
else if (lmb == 1){ | ||
|
||
Mouse.press(MOUSE_LEFT); | ||
|
||
} | ||
|
||
|
||
|
||
if (rmb == 0){ | ||
|
||
Mouse.release(MOUSE_RIGHT); | ||
|
||
} | ||
|
||
|
||
|
||
else if (rmb == 1){ | ||
|
||
Mouse.press(MOUSE_RIGHT); | ||
|
||
} | ||
|
||
|
||
|
||
if (mmb == 0){ | ||
|
||
Mouse.release(MOUSE_MIDDLE); | ||
|
||
} | ||
|
||
|
||
|
||
else if (mmb == 1){ | ||
|
||
Mouse.press(MOUSE_MIDDLE); | ||
|
||
} | ||
if (Serial.available() > 0) { | ||
Serial.readBytes(bf, 2); | ||
|
||
Mouse.move(bf[0], bf[1], 0); | ||
|
||
} | ||
else { | ||
|
||
Mouse.move(dx, dy); | ||
|
||
} | ||
} |