Видео Python folium.raster_layers.VideoOverlay() не заполняет ограничивающую рамкуPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Видео Python folium.raster_layers.VideoOverlay() не заполняет ограничивающую рамку

Сообщение Anonymous »

Я пытаюсь наложить видео в формате mp4 на карту фолиума, используя
folium.raster_layers.VideoOverlay(). В результате получается видео, которое я называю DyeVideo.html. Однако изображение не отображается в
ограничивающей рамке на карте, borders=[[lat_min,lon_min],[lat_max,lon_max]]. DyeVideo.png — это скриншот видеофайла DyeVideo.html. См. https://casconorwich.org/pages/files2.html, чтобы увидеть снимок экрана для этого и других. Видео не заполняет всю красную ограничивающую рамку. Я постараюсь объяснить, как было создано это видео. На данный момент он содержит только 5 png-фреймов, но со временем их будет около 50.
Данные получены в результате запуска числовой модели океана FVCOM, чтобы создать
распространение красителя, который вводится в океан в Каско. Бэй, штат Мэн, с течением времени. Выходные данные помещаются в массив [lat,lon,dyeconcentration], где lat,lon
задается в каждой вершине треугольной сетки, имеющей около 40 000 вершин. Для каждого из 5 раз я создаю png-файл с помощью tripcolor():
tpp = ax1.tripcolor(lat,lon,triangles,dye1[t1+k,:],cmap='jet',shading= 'gouraud')


Then save tpp as a png file:

img1=plt.savefig('tpp'+str(k+1)+str('.png'), format='png',dpi=400,bbox_inches='tight',pad_inches=0.0,transparent=True)

To see how one of these 5 png images look on a folium map, I use

folium.raster_layers.ImageOverlay следующим образом:
array1 = asarray(img1)
folium.raster_layers.ImageOverlay(
image = array1, name='Dye overlay',
bounds=[[lat_min,lon_min],[lat_max,lon_max]],
opacity=0.6, origin='upper',
mercator_project=True, cross_origin=False,
zindex=1,overlay=True, control=True,
show=True,
).add_to(map)

One of the 5 overlays on the folium map is shown in a screenshot, DyeFrame1.png on my website. You can see that this single png image projects onto the folium map exactly as it should, filling the red rectangle of the bounding box.
The next step is to build an mp4 video from the 5 png images, using cv2 VideoWriter:

#=====================
def images_to_video(image_folder, output_path, fps=0.6):
#Converts a folder of png images into a video.
images = [img for img in os.listdir(image_folder) if img.endswith("png")]
images.sort() # Ensure images are in order
frame = cv2.imread(os.path.join(image_folder, images[0]))
width,height = frame.shape[1],frame.shape[0] # here,1984,1348
video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'),fps, (width,height))

for image in images:
img_path = os.path.join(image_folder, image)
frame = cv2.imread(img_path)
video.write(frame)

video.release()
print("Video Frames2png.mp4 created successfully at:", output_path)
if __name__ == "__main__":
output_path = '/Users/true/Python1/DyeFrames/Frames2/Frames2png.mp4'
images_to_video(image_folder, output_path)
map.save('DyeFrames2.html')

#====================

So the result, Frames2png.mp4, is just a video of 5 frames of png files, each of which fit perfectly in the red bounding box.

Finally, the folium.raster_layers.VideoOverlay() is used to overlay the video Frames2png.mp4 onto the folium map:
#===================================

video = folium.raster_layers.VideoOverlay(
video_url= Frames2png.mp4,
bounds=[[lat_min,lon_min],[lat_max,lon_max]],
transparent=True,
keepAspectRatio=False,
mercator_project=True,
name="Dye Video",
opacity=0.6,
attr="Dye Overlay",
overlay= True,
autoplay=True,
control=True,
loop=True,
playsInline=True,
)
video.add_to(map)
map.save('DyeVideo.html')


#=======================================
The result is DyeVideo.html, which does not fit correctly in the red bounding box. Everything works great except for the folium.raster_layers.VideoOverlay().

I have used ffmpeg to remove any unwanted borders from the png images and Frames2png.mp4. I have also used ffmpeg to resize Frames2png.mp4 in numerous ways to increase height, etc, allowing aspect-ratio to change as necessary. In each case the bounding box seems to have no control over the size and position of the video on the folium map. When I look at the folium.raster_layers.py file, I see nothing there that would help. I'm wondering if others have had a similar problem or can give some advice. I just want to overlay a video onto a map.


Подробнее здесь: https://stackoverflow.com/questions/793 ... unding-box
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»