def test_drive(): images = glob.glob("bgr_data/2019-05-09_04-48-50/" + "*.jpg") image_num = len(images) print(image_num) hostname = socket.gethostname() run_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S') folder_name = "set_" + hostname + "_" + run_time set_path = Constant.DATA_SET_PATH + folder_name os.makedirs(set_path) sys.stdout = Logger(set_path + "/log.txt", sys.stdout) de = Detector() d = Driver() # server = Server() # client = Client() # d.client = client is_upload = True # video_stream_thread = threading.Thread(target=server.get_video_stream) # video_stream_thread.setDaemon(True) # video_stream_thread.start() # tl_state_thread = threading.Thread(target=client.get_tl_state) # tl_state_thread.setDaemon(True) # tl_state_thread.start() objects_info_dict = {} start = time.time() # i = 0 for image in images: print(image.split('/')[-1]) objects_info, objects_num, image_array = de.detect(cv2.imread(image)) d.objects_info = objects_info d.objects_num = objects_num d.image_array = image_array cmd = d.drive() # server.send_msg(cmd) print("commond sent to pi: ", cmd) # server.send_msg(cmd.encode(encoding="utf-8")) objects_info_dict[ObjInfoKey(image_array)] = objects_info print("* " * 50) cv2.waitKey(1) end = time.time() local_path = object_dict_to_csv(objects_info_dict, folder_name) print("local_path: ", local_path) print(end - start) Uploader("server_conf.conf", local_path, Constant.SERVER_DATA_PATH).upload() cv2.destroyAllWindows()
cv2.setTrackbarPos('UpperS', 'result', us) cv2.createTrackbar('LowerV', 'result', 0, 255, nothing) cv2.setTrackbarPos('LowerV', 'result', lv) cv2.createTrackbar('UpperV', 'result', 0, 255, nothing) cv2.setTrackbarPos('UpperV', 'result', uv) font = cv2.FONT_HERSHEY_SIMPLEX while 1: # Threshold the HSV image frame, hsv = get_frame() mask = cv2.inRange(hsv, lower_hsv, upper_hsv) if mode in ['ball', 'basket']: result, _, cy, _, _, h = detector.detect(frame, hsv, lower_hsv, upper_hsv) # print("Lower border: " + str(int(round(cy + h/2)))) else: result = cv2.bitwise_and(frame, frame, mask=mask) if mode == 'hough': # result = frame circles = cv2.HoughCircles(mask, cv2.HOUGH_GRADIENT, 1, 20, param1=30, param2=14, minRadius=0, maxRadius=0) if circles is not None: circles = np.uint16(np.around(circles))
self.image_idx += 1 if __name__ == '__main__': try: cam_proc = RealsenseProcessing() cam_proc.run() rate = rospy.Rate(RATE) i = 0 while not rospy.is_shutdown(): cam_proc.get_frame() ball_detector = Detector( osp.join(COLOR_CONFIG_PATH, "ball_green.txt"), "BallDetector", "ball") ball_res, cx, cy, contour_area, w, h = ball_detector.detect( cam_proc.regular_image, cam_proc.hsv) cam_proc.pub_ball.publish(Point(cx, cy, 0)) basket_detector = Detector( osp.join(COLOR_CONFIG_PATH, "basket_{}.txt".format(BASKET_COLOR)), "BasketDetector", "basket") basket_res, basket_cx, basket_cy, basket_contour_area, basket_w, basket_h = basket_detector.detect( cam_proc.regular_image, cam_proc.hsv) cam_proc.pub_basket.publish( Point(basket_cx, int(round(basket_cy + basket_h / 2)), 0)) # print("Lower border: " + str(int(round(basket_cy + basket_h/2)))) if i % int(RATE * SAVE_FREQUENCY ) == 0 and i != 0: # for debugging/analysis purposes squareness = round((float(min(w, h)) / max(w, h)) *