def test_detect(): dev = AndroidDeviceMinicap() dev._adb.start_minitouch() time.sleep(3) d = SceneDetector('txxscene') old, new = None, None while True: # time.sleep(0.3) screen = dev.screenshot_cv2() h, w = screen.shape[:2] img = cv2.resize(screen, (w/2, h/2)) # find hsv hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) hls = cv2.cvtColor(img, cv2.COLOR_BGR2HLS) _, _, V = cv2.split(hsv) V[V<150] = 0 cv2.imshow('V', V) _, _, L = cv2.split(hls) L[L<150] = 0 cv2.imshow('H', L) tic = time.clock() new = str(d.detect(img)) t = time.clock() - tic if new != old: print 'change to', new print 'cost time', t old = new for _, r in d.current_scene: x, y, x1, y1 = r cv2.rectangle(img, (x,y), (x1,y1), (0,255,0) ,2) cv2.imshow('test', img) cv2.waitKey(1)
def test_detect(): dev = AndroidDeviceMinicap() dev._adb.start_minitouch() time.sleep(3) d = SceneDetector('txxscene') old, new = None, None while True: # time.sleep(0.3) screen = dev.screenshot_cv2() h, w = screen.shape[:2] img = cv2.resize(screen, (w / 2, h / 2)) # find hsv hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) hls = cv2.cvtColor(img, cv2.COLOR_BGR2HLS) _, _, V = cv2.split(hsv) V[V < 150] = 0 cv2.imshow('V', V) _, _, L = cv2.split(hls) L[L < 150] = 0 cv2.imshow('H', L) tic = time.clock() new = str(d.detect(img)) t = time.clock() - tic if new != old: print 'change to', new print 'cost time', t old = new for _, r in d.current_scene: x, y, x1, y1 = r cv2.rectangle(img, (x, y), (x1, y1), (0, 255, 0), 2) cv2.imshow('test', img) cv2.waitKey(1)
def test_minicap(): from atx.drivers.android_minicap import AndroidDeviceMinicap cv2.namedWindow("preview") d = AndroidDeviceMinicap() while True: try: h, w = d._screen.shape[:2] img = cv2.resize(d._screen, (w/2, h/2)) cv2.imshow('preview', img) key = cv2.waitKey(1) if key == 100: # d for dump filename = time.strftime('%Y%m%d%H%M%S.png') cv2.imwrite(filename, d._screen) except KeyboardInterrupt: break cv2.destroyWindow('preview')
def test_features(): from atx.drivers.android_minicap import AndroidDeviceMinicap cv2.namedWindow("preview") d = AndroidDeviceMinicap() # r, h, c, w = 200, 100, 200, 100 # track_window = (c, r, w, h) # oldimg = cv2.imread('base1.png') # roi = oldimg[r:r+h, c:c+w] # hsv_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV) # mask = cv2.inRange(hsv_roi, 0, 255) # roi_hist = cv2.calcHist([hsv_roi], [0], mask, [180], [0,180]) # cv2.normalize(roi_hist, roi_hist, 0, 255, cv2.NORM_MINMAX) # term_cirt = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1) while True: try: w, h = d._screen.shape[:2] img = cv2.resize(d._screen, (h / 2, w / 2)) cv2.imshow('preview', img) hist = cv2.calcHist([img], [0], None, [256], [0, 256]) plt.plot(plt.hist(hist.ravel(), 256)) plt.show() # if img.shape == oldimg.shape: # # hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # # ret, track_window = cv2.meanShift(hsv, track_window, term_cirt) # # x, y, w, h = track_window # cv2.rectangle(img, (x, y), (x+w, y+h), 255, 2) # cv2.imshow('preview', img) # # cv2.imshow('preview', img) cv2.waitKey(1) except KeyboardInterrupt: break cv2.destroyWindow('preview')
def _get_mini_dev(): dev = AndroidDeviceMinicap() dev._adb.start_minitouch() time.sleep(3) return dev