def pipeline(frame): global ct, history, ROI_MASK, MASK_VALID, GRID_MATRIX_INIT, grid_matrix, frame_seq timestamp_area = frame[t_i_1_s:t_i_1_e,t_i_2_s:t_i_2_e] # cv2.imshow("cropped", timestamp_area) # cv2.waitKey(0) gray = cv2.cvtColor(timestamp_area, cv2.COLOR_BGR2GRAY) #gray = cv2.threshold(gray, 0, 255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1] #gray = cv2.medianBlur(gray, 3) text = pytesseract.image_to_string(gray) print(text) if MASK_VALID == 0: ROI_MASK = np.zeros_like(frame[:,:,0], dtype=np.uint8) np_corners = np.array(g_corners, dtype = np.int32) cv2.fillPoly(ROI_MASK, [np_corners], 255) MASK_VALID = 1 if GRID_MATRIX_INIT == 0: grid_matrix = np.zeros((int(grid_step) + 1, int(grid_step) + 1)) GRID_MATRIX_INIT = 1 #print(ROI_MASK.shape) fm = Frame(frame, g_corners, ROI_MASK, grid_matrix, grid_step, frame_seq) mpimg.imsave("current_frame.jpg", frame) results = detect(net, meta, b"current_frame.jpg") #print(fm.img.shape) for detection in results: ob = Object(detection, frame_seq) fm.add_object(ob) # update frame number frame_seq += 1 if frame_seq > FRAME_SQE_MAX: frame_seq = 0 fm.draw_boxes() fm.add_labels() fm.draw_grid() fm.color_grid() fm.color_NROI() # cv2.line(fm.box_img, (0,420), (700,420), (255,0,0)) # cv2.line(fm.box_img, (0,380), (700,380), (255,0,0)) fm.detect_crossing(ct) if len(history) > 0 : detect_crossing_with_history(fm, history.pop()) #print(len(fm.objects)) fm.plot_measurements() fm.draw_trajectory() history.append(fm) return fm.box_img