From d8f94c53a4b39387a0037fc4a32cb21bf2f07eaa Mon Sep 17 00:00:00 2001 From: ahao Date: Mon, 19 Sep 2022 13:57:55 +0800 Subject: [PATCH] track --- controller/AiController.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/controller/AiController.py b/controller/AiController.py index 714f245..92d02fe 100644 --- a/controller/AiController.py +++ b/controller/AiController.py @@ -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': @@ -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) @@ -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)) @@ -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: @@ -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])