-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse Control.py
More file actions
33 lines (26 loc) · 904 Bytes
/
Mouse Control.py
File metadata and controls
33 lines (26 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from SimpleCV import *
from pymouse import PyMouse
m = PyMouse()
desktop_size = m.screen_size()
desk_width, desk_height = desktop_size[0], desktop_size[1]
cam = Camera(0, {'width': 640, 'height': 480})
img = cam.getImage()
img_width, img_height = img.width, img.height
wd_conv = float(desk_width/img_width)
ht_conv = float(desk_height/img_height)
HUE = 40 ## Mouse will track green color on screen
disp = Display()
while not disp.isDone():
img = cam.getImage().flipHorizontal()
hsv_img = img.toHSV()
dist_img =hsv_img.hueDistance(HUE)
bin_img = dist_img.binarize(20)
eroded_img = bin_img.erode()
dilated_img = eroded_img.dilate()
blobs = dilated_img.findBlobs()
img.show()
if blobs:
blob_center = blobs[-1].centroid()
x = int(blob_center[0]*wd_conv)
y = int(blob_center[1]*ht_conv)
m.move(x, y)