def compute_descriptors(frames, pts, nbhd=(8, 8, 5)): flo = flow.get_flow(frames) nx, ny, nt = nbhd sx, sy, st = frames.shape ## eliminate points which are too close to the boundaries inds = ( (nx <= pts[0, :]) & (pts[0, :] < sx - nx) & (ny <= pts[1, :]) & (pts[1, :] < sy - ny) & (nt <= pts[2, :]) & (pts[2, :] < st - nt) ) pts = pts[:, inds] descs = [] for x, y, t in zip(*pts): sub_flo = flo[x - nx : x + nx + 1, y - ny : y + ny + 1, t - nt : t + nt + 1] xhist, _ = np.histogram(sub_flo[..., 0], bins=bins) yhist, _ = np.histogram(sub_flo[..., 1], bins=bins) xhist = xhist.astype(np.float64) / xhist.sum() yhist = xhist.astype(np.float64) / yhist.sum() descs.append(np.hstack([xhist, yhist])) return np.vstack(descs)
def main(): args = parse_opt() flow, header = get_flow(args.movie) bboxes = pick_bbox(os.path.join(args.movie, "bbox_dump")) vis_compare(args.movie, header, flow, bboxes, baseline=args.baseline, worst=args.worst)
def main(): args = parse_opt() flow, header = get_flow(args.movie) bboxes = pick_bbox(os.path.join(args.movie, "bbox_dump")) # for index, bbox in enumerate(bboxes): # if not bbox.empty: # bboxes[index] = bbox.query(f"prob >= 0.4") vis_interp(args.movie, header, flow, bboxes, baseline=args.baseline, worst=args.worst)
def main(): args = parse_opt() flow, header = get_flow(args.movie) bboxes = pick_bbox(os.path.join(args.movie, "bbox_dump")) # from eval_mot16 import MOT16 # mot = MOT16(os.path.basename(args.movie)) # bboxes = mot.pick_bboxes() if args.compare: vis_composed(args.movie, header, flow, bboxes, baseline=args.baseline, worst=args.worst) else: vis_kalman(args.movie, header, flow, bboxes, baseline=args.baseline, worst=args.worst)
def main(): args = parse_opt() if os.path.exists("flow.pkl") and not args.reset: with open("flow.pkl", "rb") as f: flow, header = pickle.load(f) else: flow, header = get_flow(args.movie, prefix=".") # flow, header = get_flow(args.movie) # with open("flow.pkl", "wb") as f: # pickle.dump((flow, header), f, pickle.HIGHEST_PROTOCOL) if os.path.exists("bboxes.pkl") and not args.reset: with open("bboxes.pkl", "rb") as f: bboxes = pickle.load(f) else: src_id = os.path.basename(args.movie) mot = MOT16_SORT(src_id) bboxes = mot.pick_bboxes() # bboxes = pick_bbox(os.path.join(args.movie, "bbox_dump")) # with open("bboxes.pkl", "wb") as f: # pickle.dump(bboxes, f, pickle.HIGHEST_PROTOCOL) vis_histogram(args.movie, header, flow, bboxes)
def eval_mot16(src_id, prefix="MOT16/train", MOT16=MOT16, thresh=0.0, baseline=False, worst=False, display=False, gop=12): mot = MOT16(src_id) bboxes = mot.pick_bboxes() movie = join(prefix, src_id) flow, header = get_flow(movie, prefix=".", gop=gop) if display: cap, out = open_video(movie, display=True) else: cap = open_video(movie, display=False) count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) kalman = KalmanInterpolator() interp_kalman_clos = lambda bboxes, flow, frame: \ interp_kalman(bboxes, flow, frame, kalman) for index, bbox in enumerate(bboxes): if not bbox.empty: bboxes[index] = bbox.query(f"prob >= {thresh}") start = time.perf_counter() for i in range(count): ret, frame = cap.read() if ret is False or i > bboxes.size: break if baseline: bbox = bboxes[i].copy() if display: frame = draw_i_frame(frame, flow[i], bbox) mot.eval_frame(bbox) kalman.reset(bbox) elif header["pict_type"][i] == "I": bbox = bboxes[i].copy() if display: frame = draw_i_frame(frame, flow[i], bbox) mot.eval_frame(bbox) kalman.reset(bbox) elif worst: if display: frame = draw_i_frame(frame, flow[i], bbox) mot.eval_frame(bbox) else: # bbox is updated by reference if display: frame = draw_p_frame(frame, flow[i], bbox, interp=interp_kalman_clos) else: interp_kalman_clos(bbox, flow[i], frame) mot.eval_frame(bbox) if display: cv2.rectangle(frame, (width - 220, 20), (width - 20, 60), (0, 0, 0), -1) cv2.putText(frame, f"pict_type: {header['pict_type'][i]}", (width - 210, 50), cv2.FONT_HERSHEY_DUPLEX, 1, (255, 255, 255), 1) out.write(frame) end = time.perf_counter() print(f"{src_id}: {count/(end-start):3.1f} FPS") # print(f"{end-start:5.2f}") cap.release() if display: out.release()
def eval_mot16_pred(src_id, model, prefix="MOT16/train", MOT16=MOT16, thresh=0.0, baseline=False, worst=False, display=False): mot = MOT16(src_id) movie = join(prefix, args.src_id) flow, header = get_flow(movie, prefix=".") if display: cap, out = open_video(movie, display=True) else: cap = open_video(movie, display=False) count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) start = time.perf_counter() for i in trange(count): ret, frame = cap.read() if ret is False: break if baseline: bbox = predict(model, frame, thresh=thresh) if display: frame = draw_i_frame(frame, flow[i], bbox) mot.eval_frame(bbox) elif header["pict_type"][i] == "I": bbox = predict(model, frame, thresh=thresh) if display: frame = draw_i_frame(frame, flow[i], bbox) mot.eval_frame(bbox) elif worst: if display: frame = draw_i_frame(frame, flow[i], bbox) mot.eval_frame(bbox) else: # bbox is updated by reference if display: frame = draw_p_frame(frame, flow[i], bbox) else: interp_linear(bbox, flow[i], frame) mot.eval_frame(bbox) if display: cv2.rectangle(frame, (width - 220, 20), (width - 20, 60), (0, 0, 0), -1) cv2.putText(frame, f"pict_type: {header['pict_type'][i]}", (width - 210, 50), cv2.FONT_HERSHEY_DUPLEX, 1, (255, 255, 255), 1) out.write(frame) end = time.perf_counter() print(f"{src_id}: {count/(end-start):3.1f} FPS") cap.release() if display: out.release()
def get_solution(enthalpy,temperature,reference_temperature,pressure,\ reference_pressure,density,reference_density,velocity,\ concentration_s1,concentration_s2,concentration_s3,\ concentration_g1,electric_potential,current_density,\ electrical_conductivity,number_density,\ delx,delt,cfl_energy,cfl_momentum,energyfluxmax,\ momentumfluxmax,reporting_interval1,reporting_interval2): ''' this function combines the entire algorithm and provides a time-marched solution Parameters: ----------- enhtalpy temperature reference_temperature pressure reference_pressure density reference_density velocity concentrations 1 through 4: B,Ni.Co,N electric_potential current_density electrical_conductivity number_density (e) delx,delt cfl_energy,cfl_momentum (if no initial value: use 125,0.75 respectively) energyfluxmax,momentumfluxmax (if no inital value: use 1e5,1.0 respectively) reporting_interval1,reporting_interval2 Returns: ----------- for now, output 2 scalar variables: number of iterations final time ''' hnref = enthalpy.copy() #used for stability condition delt_ref = delt # cfl numbers for stability condition cflen = cfl_energy cflmn = cfl_momentum cflen_ref = cfl_energy cflmn_ref = cfl_momentum #fluxes for stability condition efmax = energyfluxmax mfmax = momentumfluxmax #temperature Tnref = temperature.copy() Tnref_old = reference_temperature.copy() #pressure pxn = pressure.copy() pxn_ref = reference_pressure.copy() #density rhoxn = density.copy() rhoxn_ref = reference_density.copy() #velocity uxn = velocity.copy() #concentrations cB = concentration_s1.copy() cNi = concentration_s2.copy() cCo = concentration_s3.copy() cN = concentration_g1.copy() # electric potential phin = electric_potential.copy() #current density jn = current_density.copy() # electrical conductivity econdxn = electrical_conductivity.copy() #number density of electrons nexn = number_density.copy() nexn_ref = number_density.copy() #reference_number_density # current time time = 0 + delt_ref #final time in seconds t_terminal = 0.0005 #iteration count iterations = 0 #------------------- #file = open('output_summary.txt','a') # while (time <t_terminal): iterations += 1 delt = get_adaptive_time_step(cflen,cflmn,efmax,mfmax,\ delx,delt_ref,numpy.max(uxn)) time = time + delt mun,ktn,cpn,Rsn = get_thermophysical_properties(Tnref,cN,cB,cNi,cCo) ablrate,rhoevap,rholocal,rhoanbc,uanbc = get_ablation_properties(Tnref[0],pxn[1],\ Tnref[1],Rsn[1]) uxn = get_velocity_bc(uxn,uanbc) rhoxn = get_density_bc(rhoxn,rhoanbc) pxn = get_pressure_bc(pxn,Tnref[0],rhoxn[0],Rsn[0],\ Tnref[-1],rhoxn[-1],Rsn[-1]) rhoxn,uxn,pxn,cflmn,mflux = get_flow(pxn,rhoxn,uxn,mun,\ delx,delt,uanbc,rhoanbc) compress = get_compressibility(pxn,pxn_ref,rhoxn,rhoxn_ref) rhoB,rhoNi,rhoCo,rhoN,\ cB,cNi,cCo,cN = get_mass_diffusion(pxn,Tnref,rhoxn,uxn,cB,cNi,cCo,cN,\ delt,delx,rhoevap,rholocal) nexn,nixn,noxn,pexn = saha_algorithm(Tnref,rhoxn,cB,cNi,cCo,cN,nexn_ref) econdxn = get_electrical_conductivity(Tnref,nexn,noxn,time) Tn,hn,cflen,efmax,Tpa,Tpc = get_energy(ablrate,rhoxn,uxn,pxn,pxn_ref,Tnref,hnref,cpn,\ ktn,mun,jn,econdxn,nexn,delx,delt) pxn[:] = rhoxn[:]*Rsn[:]*Tn[:] #reference values Tnref_old = Tnref.copy() Tnref = Tn.copy() hnref = hn.copy() rhoxn_ref = rhoxn.copy() pxn_ref = pxn.copy() nexn_ref = nexn.copy() delt_ref = delt time_ref = time cflen_ref = cflen cflmn_ref = cflmn #print summary if iterations in reporting_interval1: file = open('output_summary.txt','a') file.write('---------------------------------------\n' ) file.write('current iteration is: %.3g\n' %iterations) file.write('evaporated density is: %.3g\n' %rhoevap) file.write('ablation rate is: %.3g\n' %ablrate) file.write('max compressibility is: %.3g \n' %numpy.max(compress)) file.write('time step value is: %.3g\n' %delt) file.write('current time in seconds is: %.3g\n' %time) file.write('uxn[0] velocity in [m/s] is: %.3g\n' %uxn[0]) file.write('uxn[1] velocity in [m/s] is: %.3g\n' %uxn[1]) file.write('uxn[2] velocity in [m/s] is: %.3g\n' %uxn[2]) file.write('uxn[3] velocity in [m/s] is: %.3g\n' %uxn[3]) file.write('uxn[-1] velocity in [m/s] is: %.3g\n' %uxn[-1]) file.write('uxn[-2] velocity in [m/s] is: %.3g\n' %uxn[-2]) file.write('uxn[-3] velocity in [m/s] is: %.3g\n' %uxn[-3]) file.write('max velocity is: %.3g\n' %numpy.max(uxn)) file.write('min velocity is: %.3g\n' %numpy.min(uxn)) file.write('anode density in [kg/m3] is: %.3g\n' %rhoxn[0]) file.write('rhoxn[1] density in [kg/m3] is: %.3g\n' %rhoxn[1]) file.write('rhoxn[2] density in [kg/m3] is: %.3g\n' %rhoxn[2]) file.write('rhoxn[3] density in [kg/m3] is: %.3g\n' %rhoxn[3]) file.write('rhoxn[-1] density in [kg/m3] is: %.3g\n' %rhoxn[-1]) file.write('rhoxn[-2] density in [kg/m3] is: %.3g\n' %rhoxn[-2]) file.write('rhoxn[-3] density in [kg/m3] is: %.3g\n' %rhoxn[-3]) file.write('max density is: %.3g\n' %numpy.max(rhoxn)) file.write('min density is: %.3g\n' %numpy.min(rhoxn)) file.write('Anode Temperature [K] is: %.3g\n' %Tn[0]) file.write('T[1] temperature in [K] is: %.3g\n' %Tn[1]) file.write('T[2] temperature in [K] is: %.3g\n' %Tn[2]) file.write('T[3] temperature in [K] is: %.3g\n' %Tn[3]) file.write('T[-1] temperature in [K] is: %.3g\n' %Tn[-1]) file.write('T[-2] temperature in [K] is: %.3g\n' %Tn[-2]) file.write('T[-3] temperature in [K] is: %.3g\n' %Tn[-3]) file.write('max temperature is: %.3g\n' %numpy.max(Tn)) file.write('min temperature is: %.3g\n' %numpy.min(Tn)) file.write('Anode Pressure [Pa] is: %.3g\n' %pxn[0]) file.write('p[1] pressure in [Pa] is: %.3g\n' %pxn[1]) file.write('p[2] pressure in [Pa] is: %.3g\n' %pxn[2]) file.write('p[3] pressure in [Pa] is: %.3g\n' %pxn[3]) file.write('p[-1] pressure in [Pa] is: %.3g\n' %pxn[-1]) file.write('p[-2] pressure in [Pa] is: %.3g\n' %pxn[-2]) file.write('p[-3] pressure in [Pa] is: %.3g\n' %pxn[-3]) file.write('max pressure is: %.3g\n' %numpy.max(pxn)) file.write('min pressure is: %.3g\n' %numpy.min(pxn)) file.write('momentum cfl number is: %.3g\n' %cflmn) file.write('energy cfl number is: %.3g\n' %cflen) file.write('anode temperature addition [K]: %.4g\n' %Tpa) file.write('cathode temperature addition [K]: %.4g\n' %Tpc) file.write('---------------------------------------\n') file.close() #print graphs if iterations in reporting_interval2: plot( xc,numpy.round(Tn[1:-1],decimals=10),\ 'grid location [m]','Temperature [K]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_temperature.png' %iterations) # plot( xb,numpy.round(uxn[1:-1],decimals=5),\ 'grid location [m]','velocity [m/s]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_velocity.png' %iterations) # plot( xc,numpy.round(rhoxn[1:-1],decimals=4),\ 'grid location [m]','density [kg/m3]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_density.png'%iterations) # plot( xc,numpy.round(pxn[1:-1],decimals=0),\ 'grid location [m]','pressure [Pa]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_pressure.png'%iterations) # plot( xc,numpy.round(nexn[1:-1],decimals=0),\ 'grid location [m]','ne [1/m3]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_ne.png'%iterations) # plot( xc,numpy.round(econdxn[1:-1],decimals=0),\ 'grid location [m]','econd [S/m]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_econdavg.png'%iterations) # plot( xc,numpy.round(rhoB[1:-1],decimals=4),\ 'grid location [m]','Boron Density [kg/m3]','time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_rhoB.png' %iterations) # plot( xc,numpy.round(rhoNi[1:-1],decimals=4),\ 'grid location [m]','Nickel Density [kg/m3]','time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_rhoNi.png' %iterations) # plot( xc,numpy.round(rhoCo[1:-1],decimals=4),\ 'grid location [m]','Cobalt Density [kg/m3]','time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_rhoCo.png' %iterations) # plot( xc,numpy.round(rhoN[1:-1],decimals=4),\ 'grid location [m]','Nitrogen Density [kg/m3]','time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_rhoN.png' %iterations) #check for anode steady state: # if numpy.abs(Tnref[0]-Tnref_old[0]) <l2_target and iterations>1e6: # Tnref[0] = Tnref_old[0] # print('anode has reached steady state') #check for overall steady state if (numpy.all(numpy.abs(Tnref[:]-Tnref_old[:]) < l2_target)==True): plot( xc,numpy.round(Tn[1:-1],decimals=10),\ 'grid location [m]','Temperature [K]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_temperature.png' %iterations) # plot( xb,numpy.round(uxn[1:-1],decimals=5),\ 'grid location [m]','velocity [m/s]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_velocity.png' %iterations) # plot( xc,numpy.round(rhoxn[1:-1],decimals=4),\ 'grid location [m]','density [kg/m3]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_density.png'%iterations) # plot( xc,numpy.round(pxn[1:-1],decimals=0),\ 'grid location [m]','pressure [Pa]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_pressure.png'%iterations) # plot( xc,numpy.round(nexn[1:-1],decimals=0),\ 'grid location [m]','ne [1/m3]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_ne.png'%iterations) # plot( xc,numpy.round(econdxn[1:-1],decimals=0),\ 'grid location [m]','econd [S/m]', 'time= %.4g sec' %time) pyplot.savefig('./plots/%.5g_econdavg.png'%iterations) file.write('entire domain has reached steady state\n') file.write('terminal time is %.4g\n' %time) file.write('end of computation, see you later!\n') break #check for end of computation if (time >= t_terminal): file.write('max computational time reached.if steady state not achieved, increase terminal time\n') return iterations,time