【问题标题】:How to add matplotlib plot below and image in opencv如何在下面添加matplotlib图并在opencv中添加图像
【发布时间】:2021-07-08 16:20:54
【问题描述】:

我想在图像底部添加两个图。它应该是这样的:

dog

plot(两个图看起来非常相似)

我想将这两张图片结合在一起,专门将情节附加到狗图片的底部。我希望结果看起来像:

此链接有助于将绘图转换为正确的图像格式,但我不知道如何将它们附加到主图像

Combining cv2.imshow() with matplotlib plt.show() in real time

编辑

高级伪代码:

import cv2
import pandas
import matplotlib.pyplot as plt


vid = cv2.VideoCapture('video.mp4')
global data
data = pd.read_csv('data.csv')

assert len(data) == cv2.CAP_PROP_FRAMES_COUNT()

def pipeline(frame):

    frame_index = next(dfi[0])
    current_plot1 = plt.plot(df.time[:frame_index], df.data1[:frame_index]
    current_plot2 = plt.plot(df.time[:frame_index], df.data2[:frame_index]
    
    # add plots to frame somehow here
    frame = frame+current_plot1+current_plot2
    return frame

# write video
dfi = df.iterrows()
video = VideoFileClip(vid)
out_video = video.fl_image(pipeline)
out_video.write_videofile("vidout.mp4", temp_audiofile='temp-audio.m4a', remove_temp=True, codec="libx264", audio_codec="aac")

【问题讨论】:

  • opencv 图像会更新还是静态的?如果它是静态的,你可以做一个简单的imshow,那么你可以像这样安排它们:matplotlib.org/stable/tutorials/intermediate/…
  • 理想情况下它可以更新。我的总体目标是制作一个视频,其中狗的图像是许多帧中的 1 个,并且情节会根据每帧的附加数据进行更新。
  • 对不起,如果我听起来很愚蠢,所以你想把cv2.imshow 创建两个底部图并动态更新它们的窗口放入?还是从cv2 中捕获的图像/帧到matplotlib 中的几个帧,最后用预处理数据创建一个电影?
  • 别担心,我更新了一些伪代码以提供高级概述

标签: python image opencv matplotlib image-processing


【解决方案1】:

在初始化绘图时,首先将plot1 = plt.figure() 用于plot2 = plt.figure()

然后水平连接图

combined_plot=plt.hconcat([plot1,plot2])

然后使用垂直连接这些

final_img=plt.vconcat([dog_img,combined_plot])

return final_img

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    • 2018-02-26
    • 2012-04-01
    • 2021-02-16
    • 1970-01-01
    • 2013-07-29
    • 1970-01-01
    相关资源
    最近更新 更多