我有来自无人机的数据。第一个表包含每帧中的行人数据。行人数据具有行人Id、帧、x_est、y_est、v_abs。第二个表是车辆的数据。车辆数据包括车辆Id、车架、x_est、y_est、速度_est。例如,在第1帧中,我有39名行人和两辆车。我想创建一个包含以下信息的新表:
-
第一列是每个框架中每个行人和每个车辆之间的距离。例如,我有39名行人和2辆车:
d1=sqrt((ped1_x-veh1_x)^2+(ped1_y-veh1_y)^2)
d2=sqrt((ped1_x-veh2_x)^2+(ped1_y-veh2_y)^2)
d3=sqrt((ped2_x-veh1_x)^2+(ped2_y-veh1_y)^2)
d4=sqrt((ped2_x-veh2_x)^2+(ped2_y-veh2_y)^2)
等等
- 第二列和第三列是行人和车辆的相关速度。例如,如果我得到d1,那么我必须包括ped1的速度和veh1的速度。如果我得到d2,那么我必须包括ped1的速度和veh2的速度,依此类推
我有116帧。我想用python或Matlab编写代码来完成这些任务。我用以下代码尝试了python,但没有成功,因为车辆的数据有182行,行人的数据有3950:
if peds["frame"] == vehs["frame"]:
distance = math.sqrt(((peds.x_est-vehs.x_est)**2)+((peds.y_est - vehs.y_est))**2)
我想在每帧上添加一个for循环如何修改代码以在每个帧上循环并计算这些对象之间的距离
这是一个数据示例
行人数据:id01.2.3.4.5.6.7.8.9101112131415161718192021222324252627282930313233343536373839
框架11.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1
x_est15.3125124314.6295729114.8194055416.26125414.2506523513.7191374412.7703715611.8214933311.0245226610.45507699.96250044210.5684594711.1767290311.7075849514.2881674313.4160519611.631674611.479762413.339530110.9865130611.8976353112.4671459313.9089804911.176110589.2027512611.1008673211.6696830512.8843725913.3770845514.1748578214.8194356515.6538854917.704620818.7670333319.2218897119.0321902819.6393016819.2609578820.5496375421.87812196
y_est24.0414696723.8512282222.5997381921.4611199822.2584543122.5237212922.3708605622.8269573322.789277822.7894167821.4224305421.4988412121.4604575221.5368357719.8664281719.7535100219.2979112517.2487568216.5657825514.9710420910.113585719.7337652669.1652587698.1022463218.2168362766.6599102776.7742662832.8653687693.055532634.4592666684.1937043624.4206058844.269811893.5479871914.0421008154.8764478655.2942385446.0907772163.9661600634.762697865
v_abs2.4590071572.6543345713.3154034553.3895738033.3785669293.0455395123.230117852.9250994752.5849987212.9016420562.8118924482.1510193421.963474141.5005679273.5409854512.7099921153.2679725653.3950631492.7217796764.0122120990.8808542340.8139331370.7043726210.9120897880.5495926633.0077994281.9789638983.447573963.157371623.5293827823.55561663.4097645931.1707652471.5807097451.0852287810.9222791320.8026989161.8758943010.8049754251.205954878
车辆数据:
id900901900901900901900901900901900901900901900901900901900901900901900901900901900901900901900901900901900901900901900901
框架11.2.2.3.3.4.4.5.5.6.6.7.7.8.8.9910101111121213131414151516161717181819192020
x_est13.1218153820.7967654413.0183053220.7344718212.9205608920.6530159512.7798482320.5242220212.6714709320.4520746812.5650421620.3405099912.4570428320.2339286312.3512247720.1300072812.2482541120.0307037112.1511169119.935910112.0468534719.849725711.9387037719.759304511.8250718519.6669571411.7078536219.5781313311.6009053919.4850911311.4817496319.3930588311.3679085319.2987647511.2606640419.2193889611.1453806619.1265848411.0214947219.02832259
y_est12.48663134612.0494522512.5075752212.0924305312.5315013612.1411909912.5629512812.2017877312.5903490612.2245160912.6094548212.280052912.6188541512.3194756312.6284237612.3579949212.6401633912.4040304612.6669646612.4434368612.6739802612.482889312.6921731412.5276145612.7040441812.5674796912.7120138712.6089307912.735243512.6513014512.7594809212.6893576112.7703976112.7236253712.7818266812.7686413912.8047799612.8071966312.8214140112.8529026
速度测试2.6072514942.4803790412.6071607142.4795432112.606604452.4789395632.609844362.4825172292.6101248882.4794124312.6100347082.4819933152.6099250212.4833030752.6095048672.4843050082.6086868752.4851972392.6072935122.4850289912.6064776342.4835090582.606650342.4830078572.6076578562.4824423432.6092801142.4813484082.6093744382.4810882292.6120942322.4802425672.6132469152.4794869092.6129465222.4765817262.6149721242.4759038082.6188898312.47716006
提前感谢
只要用语言思考这个问题。对于每个行人入口和每个汽车入口,如果帧数匹配,则计算它们之间的距离,并添加新行。没什么。
ped_id = "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39"
ped_frame = "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"
ped_x_est = "15.31251243 14.62957291 14.81940554 16.261254 14.25065235 13.71913744 12.77037156 11.82149333 11.02452266 10.4550769 9.962500442 10.56845947 11.17672903 11.70758495 14.28816743 13.41605196 11.6316746 11.4797624 13.3395301 10.98651306 11.89763531 12.46714593 13.90898049 11.17611058 9.20275126 11.10086732 11.66968305 12.88437259 13.37708455 14.17485782 14.81943565 15.65388549 17.7046208 18.76703333 19.22188971 19.03219028 19.63930168 19.26095788 20.54963754 21.87812196"
ped_y_est = "24.04146967 23.85122822 22.59973819 21.46111998 22.25845431 22.52372129 22.37086056 22.82695733 22.7892778 22.78941678 21.42243054 21.49884121 21.46045752 21.53683577 19.86642817 19.75351002 19.29791125 17.24875682 16.56578255 14.97104209 10.11358571 9.733765266 9.165258769 8.102246321 8.216836276 6.659910277 6.774266283 2.865368769 3.05553263 4.459266668 4.193704362 4.420605884 4.26981189 3.547987191 4.042100815 4.876447865 5.294238544 6.090777216 3.966160063 4.762697865"
ped_v_abs = "2.459007157 2.654334571 3.315403455 3.389573803 3.378566929 3.045539512 3.23011785 2.925099475 2.584998721 2.901642056 2.811892448 2.151019342 1.96347414 1.500567927 3.540985451 2.709992115 3.267972565 3.395063149 2.721779676 4.012212099 0.880854234 0.813933137 0.704372621 0.912089788 0.549592663 3.007799428 1.978963898 3.44757396 3.15737162 3.529382782 3.5556166 3.409764593 1.170765247 1.580709745 1.085228781 0.922279132 0.802698916 1.875894301 0.804975425 1.205954878"
veh_id = "900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901 900 901"
veh_frame = "1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20"
veh_x_est = "13.12181538 20.79676544 13.01830532 20.73447182 12.92056089 20.65301595 12.77984823 20.52422202 12.67147093 20.45207468 12.56504216 20.34050999 12.45704283 20.23392863 12.35122477 20.13000728 12.24825411 20.03070371 12.15111691 19.9359101 12.04685347 19.8497257 11.93870377 19.7593045 11.82507185 19.66695714 11.70785362 19.57813133 11.60090539 19.48509113 11.48174963 19.39305883 11.36790853 19.29876475 11.26066404 19.21938896 11.14538066 19.12658484 11.02149472 19.02832259"
veh_y_est = "12.48631346 12.04945225 12.50757522 12.09243053 12.53150136 12.14119099 12.56295128 12.20178773 12.59034906 12.22451609 12.60945482 12.2800529 12.61885415 12.31947563 12.62842376 12.35799492 12.64016339 12.40403046 12.66696466 12.44343686 12.67398026 12.4828893 12.69217314 12.52761456 12.70404418 12.56747969 12.71201387 12.60893079 12.7352435 12.65130145 12.75948092 12.68935761 12.77039761 12.72362537 12.78182668 12.76864139 12.80477996 12.80719663 12.82141401 12.8529026"
veh_vel_est = "2.607251494 2.480379041 2.607160714 2.479543211 2.60660445 2.478939563 2.60984436 2.482517229 2.610124888 2.479412431 2.610034708 2.481993315 2.609925021 2.483303075 2.609504867 2.484305008 2.608686875 2.485197239 2.607293512 2.485028991 2.606477634 2.483509058 2.60665034 2.483007857 2.607657856 2.482442343 2.609280114 2.481348408 2.609374438 2.481088229 2.612094232 2.480242567 2.613246915 2.479486909 2.612946522 2.476581726 2.614972124 2.475903808 2.618889831 2.47716006"
import math
import pandas as pd
def convert(s,cvt):
return [cvt(k) for k in s.split()]
peds = list(zip(
convert(ped_id,int),
convert(ped_frame,int),
convert(ped_x_est,float),
convert(ped_y_est,float),
convert(ped_v_abs,float)
))
cars = list(zip(
convert(veh_id,int),
convert(veh_frame,int),
convert(veh_x_est,float),
convert(veh_y_est,float),
convert(veh_vel_est,float)
))
newdata = []
for ped in peds:
for car in cars:
if ped[1] != car[1]:
continue
dist = math.sqrt((ped[2]-car[2])**2 + (ped[3]-car[3])**2)
newdata.append( (ped[0], car[0], dist, ped[4], car[4]) )
df = pd.DataFrame( newdata, columns=("ped id", "car id", "distance", "ped vel", "car vel"))
print(df)
输出:
ped id car id distance ped vel car vel
0 0 900 11.760986 2.459007 2.607251
1 0 901 13.186566 2.459007 2.480379
2 1 900 11.464494 2.654335 2.607251
3 1 901 13.316012 2.654335 2.480379
4 2 900 10.254910 3.315403 2.607251
.. ... ... ... ... ...
75 37 901 6.153415 1.875894 2.480379
76 38 900 11.303343 0.804975 2.607251
77 38 901 8.087069 0.804975 2.480379
78 39 900 11.675921 1.205955 2.607251
79 39 901 7.366554 1.205955 2.480379
[80 rows x 5 columns]