Skip to content

Commit

Permalink
track
Browse files Browse the repository at this point in the history
  • Loading branch information
ahao committed Sep 19, 2022
1 parent 07267e5 commit d8f94c5
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions controller/AiController.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def __init__(self,qt_comunicate=None, sleeptime=0.01,accuracy=0,provider='CPUExe
try:
self.ai = ORDML(provider)
tracker_types = ['BOOSTING', 'MIL','KCF', 'TLD', 'MEDIANFLOW', 'GOTURN', 'MOSSE', 'CSRT']
tracker_type = tracker_types[6]
tracker_type = tracker_types[4]
if tracker_type == 'GOTURN':
tracker = cv.legacy.TrackerBoosting_create()
elif tracker_type == 'MIL':
Expand Down Expand Up @@ -272,7 +272,7 @@ def recognize(self):
cvimg = screenshot_to_cv(img)
# cvimg = resize_img(cvimg,self.resize_rate)
# try track
if self.box and time.time()-self.detecttime<0.5:
if self.box and time.time()-self.detecttime<1:
trackimg = cv.cvtColor(cvimg,cv.COLOR_BGRA2BGR)
trackimg,_ = self.ai.circle_mask(trackimg)
ok,bbox = self.tracker.update(trackimg)
Expand All @@ -283,7 +283,7 @@ def recognize(self):

boxcenter = (
round(bbox[0]+(bbox[2]/2)),
round(bbox[1]+(bbox[3]/2)),
round(bbox[1]+(bbox[3]/5)),
)
cv.line(trackimg,center,boxcenter,(255,255,255))

Expand All @@ -306,14 +306,18 @@ def recognize(self):
self.box = bbox
self.detecttime = time.time()

self.tracker = cv.legacy.TrackerMOSSE_create()
# self.tracker = cv.legacy.TrackerMOSSE_create()
# self.tracker = cv.TrackerGOTURN_create()
self.tracker = cv.legacy.TrackerMedianFlow_create()
# tracker = cv.TrackerCSRT_create()
self.tracker.init(trackimg,bbox)

cv.line(img,center,boxcenter,(255,255,255))
# cv.line(img,center,boxcenter,(255,255,255))

# movex = int((boxcenter[0]-center[0])*self.xrate)
# movey = int((boxcenter[1]-center[1])*self.yrate)
# self.qt_comunicate.update.emit({"move":(movex,movey)})

movex = int((boxcenter[0]-center[0])*self.xrate)
movey = int((boxcenter[1]-center[1])*self.yrate)
self.qt_comunicate.update.emit({"move":(movex,movey)})
# filename = "E:/Video/ai/"+str(time.time())+".jpg"
# cv.imwrite(filename,img)
else:
Expand All @@ -335,7 +339,7 @@ def findclose(self,boxs,center,w,h):
# print(b[2]*b[3],w*h,(b[2]*b[3])/(w*h))
boxcenter_t = (
round(b[0]+(b[2]/2)),
round(b[1]+(b[3]/2)),
round(b[1]+(b[3]/5)),
)
x = int(boxcenter_t[0]-center[0])
y = int(boxcenter_t[1]-center[1])
Expand Down

0 comments on commit d8f94c5

Please sign in to comment.