-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetection.py
43 lines (35 loc) · 1.07 KB
/
detection.py
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
34
35
36
37
38
39
40
41
42
43
from vision import ItemVision
import cv2 as cv
from threading import Thread, Lock
class Detection:
# Threading properties
stopped = True
lock = None
rectangles = []
# Properties
vision_skills = None
screenshot = None
def __init__(self, item_image_path):
# Create a thread lock object
self.lock = Lock()
# Load item image
self.vision_skills = ItemVision(item_image_path)
def update(self, screenshot):
self.lock.acquire()
self.screenshot = screenshot
self.lock.release()
def start(self):
self.stopped = False
t = Thread(target=self.run)
t.start()
def stop(self):
self.stopped = True
def run(self):
while not self.stopped:
if not self.screenshot is None:
# Do object detection
rectangles = self.vision_skills.find(self.screenshot, 0.75)
# Lock thread while updating results
self.lock.acquire()
self.rectangles = rectangles
self.lock.release()