Wolfram 语言

计算摄影

通过图像元数据对行程作分析

利用照片及其元数据,可以通过地理计算来分析和可视化葡萄牙里斯本的一次徒步旅行.

导入并分析旅行期间拍摄的照片集.

In[1]:=
Click for copyable input
files = Map[ img \[Function] ExampleData[img, "FilePath"], ExampleData[{"TestImageSet", "Lisbon2016"}] ];

收集一个关联中所需的所有信息.

In[2]:=
Click for copyable input
labels = {"Thumbnail", "DateTime", "GeoPosition"};
In[3]:=
Click for copyable input
dataSet = Dataset@Map[ file \[Function] AssociationThread[ labels -> Import[file, {labels}, IncludeMetaInformation -> False]], files ]
Out[3]=

图示图片拍摄的位置.

In[4]:=
Click for copyable input
gps = dataSet[[All, "GeoPosition"]]; GeoGraphics[GeoMarker@gps, GeoRangePadding -> Quantity[100, "Meters"]]
Out[4]=

计算拍摄所有照片并返回所经过的步行距离.

In[5]:=
Click for copyable input
closeLoop = path \[Function] Append[path, First[path]];
In[6]:=
Click for copyable input
sortedGPS = closeLoop@ Normal@dataSet[SortBy["DateTime"], Take[#GeoPosition, All, 2] &]; UnitConvert[ TravelDistance[sortedGPS, TravelMethod -> "Walking"], "Kilometers"]
Out[6]=

按时间顺序,将拍摄所有照片所经过的路径可视化.

In[7]:=
Click for copyable input
travel = TravelDirections[sortedGPS, TravelMethod -> "Walking"]
Out[8]=
In[9]:=
Click for copyable input
Animate[ GeoGraphics[{ Style[Normal@travel["Dataset"][1 ;; n, "Path"], Thick, Red], dataSet[All, GeoMarker[Take[#GeoPosition, All, 2], #Thumbnail] &]}, GeoRangePadding -> Quantity[200, "Meters"] ], {n, 1, Length[travel["Dataset"]] + 1, 1} ]
播放动画
停止播放动画

计算并图示本来可以使用的最短路径.

In[10]:=
Click for copyable input
optimalPath = FindShortestTour[Normal@sortedGPS, DistanceFunction -> (QuantityMagnitude[ TravelDistance[{#1, #2}, TravelMethod -> "Walking"], "Kilometer"] &)]
Out[10]=
In[11]:=
Click for copyable input
Quantity[First@optimalPath, "Kilometers"]
Out[11]=
In[12]:=
Click for copyable input
shortestGPS = sortedGPS[[Last@optimalPath]];
In[13]:=
Click for copyable input
shortestTravel = TravelDirections[shortestGPS, TravelMethod -> "Walking"]
Out[14]=
In[15]:=
Click for copyable input
Animate[ GeoGraphics[{ Style[Normal@shortestTravel["Dataset"][1 ;; n, "Path"], Thick, Blue], dataSet[All, GeoMarker[Take[#GeoPosition, All, 2], #Thumbnail] &]}, GeoRangePadding -> Quantity[200, "Meters"] ], {n, 1, Length[shortestTravel["Dataset"]] + 1, 1} ]
播放动画
停止播放动画

相关范例

de en es fr ja ko pt-br ru