def roi_points(): global dict dict=request.get_json() with open(file_path.get()+'/demo_zones_1.csv', 'w') as writeFile: writer = csv.writer(writeFile) writer.writerow(['Z1',int(dict['point_set_1'][0][0]),int(dict['point_set_1'][0][1]), int(dict['point_set_1'][1][0]), int(dict['point_set_1'][1][1]), int(dict['point_set_1'][2][0]), int(dict['point_set_1'][2][1]), int(dict['point_set_1'][3][0]), int(dict['point_set_1'][3][1])]) print("points") return "ok"
def global_init(self,h_stack=3,vstack=2, session_runner=None): # print(dict) K.clear_session() self.config_path = input_path.get()+"/config.json" weights_path = model_path.get()+"/full_yolo_detergent_and_maggie.h5" rack_cord=None # print(self.rack_dict) if(self.rack_dict!=None): if(self.rack_dict['point_set_1']!=None): rack_cord = self.rack_dict['point_set_1'].copy() self.check_flag = 1 # print(self.rack_range) temp=rack_cord[2] rack_cord[2]=rack_cord[3] rack_cord[3]=temp # print(self.check_flag ) # print(rack_cord) # self.rack_range=[(400,205),(1150,205),(400,700),(1150,700)] # self.rack_range=[[428,202],[1143,212],[1116,682],[469,682]] if(self.check_flag==1): self.horizontal_stacks=h_stack self.vertical_stacks=vstack self.shelfs_matrix = [[None for x in range(self.vertical_stacks)] for y in range(self.horizontal_stacks)] self.left_x=rack_cord[0][0] self.right_x=rack_cord[1][0] self.top_y=rack_cord[0][1] self.bottom_y=rack_cord[2][1] shelf_count=1 self.shelf_vsize=(self.bottom_y-self.top_y)/self.horizontal_stacks self.shelf_hsize=(self.right_x-self.left_x)//self.vertical_stacks for i in range(0,self.horizontal_stacks): for j in range(0,self.vertical_stacks): self.shelfs_matrix[i][j]=(j*self.shelf_hsize+self.left_x,i*self.shelf_vsize+self.top_y) self.shelf_dict["shelf"+str(shelf_count)]=(j*self.shelf_hsize+self.left_x,i*self.shelf_vsize+self.top_y) shelf_count+=1 self.labels=[0,1,2,3,4,5] self.detergent_range=self.shelf_dict["shelf1"] self.mineralWater_range=self.shelf_dict["shelf2"] self.biscuit_range=self.shelf_dict["shelf3"] self.lays_range=self.shelf_dict["shelf4"] self.noodles_range=self.shelf_dict["shelf5"] self.coke_range=self.shelf_dict["shelf6"] self.labels_dict={1:"detergent",4:"noodles",0:"lays",2:"mineral_water",3:"coke",5:"biscuit"} self.product_range={2:self.mineralWater_range,1:self.detergent_range,5:self.biscuit_range,4:self.noodles_range,3:self.coke_range,0:self.lays_range} self.shelf_product_type=['detergent','mineral_water','biscuit','lays','noodles','coke'] #model Load with open(self.config_path) as config_buffer: self.config = json.load(config_buffer) self.yolo = YOLO(backend=self.config['model']['backend'], input_size=self.config['model']['input_size'], labels=self.config['model']['labels'], max_box_per_image=self.config['model']['max_box_per_image'], anchors=self.config['model']['anchors']) print(weights_path) self.yolo.load_weights(weights_path) print("successfull") return True else: return False
cv2.imwrite('../../../SmartRetailDashboard/src/assets/rack_image.jpg', image) # cv2.imwrite('/home/developer/workspaces/Angular-Dashboard-master/src/assets/rack_image.jpg', image) break # detector = YOLOObjectDetectionAPI('yolo_api', True) detector = TFObjectDetectionAPI( PRETRAINED_faster_rcnn_inception_v2_coco_2018_01_28, image.shape, 'tf_api', True) detector.use_session_runner(session_runner) detector_ip = detector.get_in_pipe() detector_op = detector.get_out_pipe() detector.use_threading() detector.run() config_path = input_path.get() + "/config.json" with open(config_path) as config_buffer: config = json.load(config_buffer) retail_yolo_detector = YOLO( input_size=config['model']['input_size'], labels=config['model']['labels'], max_box_per_image=config['model']['max_box_per_image'], anchors=config['model']['anchors']) retail_yolo_detector.use_session_runner(session_runner) retail_yolo_detector.use_threading() yolo_ip = retail_yolo_detector.get_in_pipe() yolo_op = retail_yolo_detector.get_out_pipe() yolo_input = Pipe() retail_yolo_detector.run() Thread(target=mlt.run).start()
Thread(target=mlt.run, args=(session_runner,)).start() stock_image_in = mlt.image_in_pipe stock_zone_in = mlt.zone_detection_in_pipe tracking_in_pipe = mlt.tracking_in_pipe flag_in_pipe = mlt.flag_in_pipe stock_image_in.push(image) age_in_pipe = mlt.age_in_pipe age_api_runner.runner(age_in_pipe, session_runner, cam_id=1) while True: ret, flag = flag_in_pipe.pull() if ret and flag is True: break tracker = OFISTObjectTrackingAPI(flush_pipe_on_read=True, use_detection_mask=False, conf_path=input_path.get() + "/demo_zones_1.csv") tracker.use_session_runner(session_runner) trk_ip = tracker.get_in_pipe() trk_op = tracker.get_out_pipe() tracker.run() def read(): while True: ret, image = cap.read() if not ret: continue image = image.copy() stock_image_in.push(image) # image = cv2.resize(image, (int(image.shape[1] / 2), int(image.shape[0] / 2))) detector_ip.push(Inference(image))
def global_init(self, session_runner=None): self.config_path = input_path.get() + "/config.json" with open(self.config_path) as config_buffer: self.config = json.load(config_buffer) rack_cord = None check_flag = 0 if (self.rack_dict != None): if (self.rack_dict['point_set_2'] != None): rack_cord = self.rack_dict['point_set_2'].copy() check_flag = 1 temp = rack_cord[2] rack_cord[2] = rack_cord[3] rack_cord[3] = temp if (check_flag == 1): self.horizontal_stacks = self.config["global_init"]["h_stack"] self.vertical_stacks = self.config["global_init"]["v_stack"] self.promo_number = self.config["global_init"]["promo_shelf"] self.promo_check = self.config["global_init"]["is_promo"] self.product_id = [ "product-2jn47kl2g", "product-2jn47jpre", "product-2jn47jtqm", "product-2jmvu04vh", "product-2jn47daux", "product-2jmvrhrxd" ] # self.product_id = ["product-2jn47jtqm", "product-2jn47jpre", "product-2jn47kl2g", "product-2jmvrhrxd", # "product-2jn47daux", "product-2jmvu04vh"] # self.shelf_product_type = ['biscuit', 'detergent', 'mineral_water', 'coke', 'noodles', 'coke'] self.shelfs_matrix = [[None for x in range(self.vertical_stacks)] for y in range(self.horizontal_stacks)] self.left_x = rack_cord[0][0] self.right_x = rack_cord[1][0] self.top_y = rack_cord[0][1] self.bottom_y = rack_cord[2][1] shelf_count = 1 self.shelf_vsize = (self.bottom_y - self.top_y) / self.horizontal_stacks self.shelf_hsize = (self.right_x - self.left_x) // self.vertical_stacks offset = 0 for i in range(0, self.horizontal_stacks): for j in range(0, self.vertical_stacks): self.shelfs_matrix[i][j] = (j * self.shelf_hsize + self.left_x, i * self.shelf_vsize + self.top_y + offset) self.shelf_dict["shelf" + str(shelf_count)] = (j * self.shelf_hsize + self.left_x, i * self.shelf_vsize + self.top_y + offset) shelf_count += 1 # self.shelf_product_type = ['detergent', 'mineral_water', 'biscuit', 'lays', 'noodles', 'coke'] self.shelf_product_type = [ 'biscuit', 'detergent', 'mineral_water', 'coke', 'noodles', 'lays' ] self.labels_dict = { 1: "detergent", 4: "noodles", 0: "lays", 2: "mineral_water", 3: "coke", 5: "biscuit" } # shelfno: product label # self.product_shelf = {1: 1, 2: 2, 3: 5, 4: 0, 5: 4, 6: 3} pshelf = self.config["global_init"]["product_shelf"] for key, value in pshelf.items(): self.product_shelf[int(key)] = value print("successfull") return True else: return False