def remove_existing_annotations(command): with PlutoDB() as conn: conn.execute(f""" WITH captures AS ( {command} ), annotations as ( DELETE FROM "Annotations" WHERE "CaptureId" IN (SELECT "CaptureId" from captures) RETURNING "AnnotationId" ) DELETE FROM "AnnotationHistory" where "AnnotationId" IN (SELECT * FROM annotations) RETURNING "AnnotationId"; """) print(f"Removed {len(conn.fetch())} existing annotations") conn.execute(f""" with captures AS ( {command} ) UPDATE "Captures" set "Trusted" = False where "CaptureId" IN (SELECT "CaptureId" FROM captures) returning "CaptureId"; """) print(f"Reset trusts for {len(conn.fetch())} captures") conn.connection.commit()
def set_trusted(url, headers, capture, detections): url = os.path.join(url, 'api/v1/captures?setsReviewed=false') trust_all = True # Implicitly meaning that we trusts captures without detections too for name, cls, x1, y1, x2, y2, conf in detections: trust_all &= name_to_trust[name] < conf * 100 if trust_all: with PlutoDB() as conn: conn.execute(f""" UPDATE "Captures" set "Trusted" = {trust_all} WHERE "CaptureId" = '{capture.CaptureId}' RETURNING "CaptureId" """) # print(f"Updated {len(conn.fetch())} capture as trusted") conn.connection.commit() return trust_all
'--store-asymmetric-conf', action="store_true", help= "Store CSV of image URLs with very asymmetric class and object confidences" ) parser.add_argument( '--refresh', action='store_true', help= "If set, will refresh materialized view if any captures were trusted") # Setup args = parser.parse_args() if args.list_municipalities: with PlutoDB() as c: c.execute("""SELECT "Municipality" FROM "Municipalities";""") print(c.fetch()) sys.exit(0) url = f"https://{args.env}.api.plutomap.com" user = args.user or os.environ.get('PLUSER') password = args.password or os.environ.get('PLPASSWORD') assert user is not None and password is not None, "No Pluto credentials provided" token = authenticate(url, user, password) # Fetch images and prepare db command = get_command(command=args.command, municipalities=args.municipalities, routeId=args.route_id, routeFromCapture=args.route_from_capture,
def get_captures(command): with PlutoDB() as conn: conn.execute(command) return conn.fetch()
type=int, help="Quadratic video resolution") parser.add_argument('--route-id', default='a1c14b6f-e1be-46d4-a45a-2e752760b8af', help="Route id") parser.add_argument('--from-file', help='Get order of filenames from file instead of DB') args = parser.parse_args() if args.from_file is not None: df = pd.DataFrame(get_ordered_files(args.from_file), columns=['ImgName']) else: with PlutoDB() as conn: conn.execute(f""" SELECT "ImgName" FROM "Captures" t1 JOIN "Positions" t2 on t1."PositionId" = t2."PositionId" WHERE t2."RouteId" = '{args.route_id}' ORDER BY t1."DetectedAt" """) df = conn.fetch() videodims = (args.dim, args.dim) # fourcc = cv2.VideoWriter_fourcc(*'avc1') fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') video = cv2.VideoWriter(f"{os.path.basename(args.image_dir)}.mp4", fourcc, args.fps, videodims)