gpt4 book ai didi

python - 在来自 opencv 视频捕获的视频中使用 tensorflow 检测对象

转载 作者:太空宇宙 更新时间:2023-11-03 23:09:43 25 4
gpt4 key购买 nike

我想使用 tensorflow MobileNet ( https://www.tensorflow.org/hub/tutorials/image_retraining#training ) 检测视频中的对象。我已经尝试了很多方法将 videocapture opencv 中的视频帧放入 tensorflow 图像,但我仍然无法运行它。我们如何在 tensorflow 的视频中检测到该对象?

这是检测图像中该对象类别的方法

python label_image.py \
--graph=/tmp/output_graph.pb --labels=/tmp/output_labels.txt \
--input_layer=Placeholder \
--output_layer=final_result \
--input_height=224 --input_width=224 \
--image=$HOME/flower_photos/daisy/21652746_cc379e0eea_m.jpg

我想把它应用到像这样的视频上

while(cap.isOpened()):
ret, frame = cap.read()
if ret:
label_image --graph=../tf_files/retrained_graph.pb --image=frame

但是我无法将opencv视频帧放入tensorflow函数

最佳答案

您可以使用与使用 moviepy 的方法类似的方法从视频中提取帧:

from moviepy.editor import VideoFileClip

clip = VideoFileClip(video_file)

video_duration = clip.duration

intervals = range(3, int(video_duration), 3) #suposing you want a frame every 3 seconds of the video


for t in intervals:
clip_file = "frame_num_%d.png"%t
clip.save_frame(clip_file, t)

让我知道这是否有助于为您澄清事情。

关于python - 在来自 opencv 视频捕获的视频中使用 tensorflow 检测对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52528251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com