yolo v3 如何提取检测到的物体的图像 [英] yolo v3 how to extract an image of a detected object

查看:32
本文介绍了yolo v3 如何提取检测到的物体的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个检测物体的项目,我正在使用 Anaconda 提取 yolo v3 检测到的物体的图像.这就是我安装 Python 并运行 yolo v3 的方式:https://github.com/统治gt09/yolov3workflow/tree/master/2_YoloV3_Execute问题是我对 Python 一无所知.是否可以在视频运行时提取图像并将它们存储在单独的文件中?

I'm working on a project to detect objects, and I'm working on extracting images of objects that are getting detected by yolo v3 using Anaconda. This is how I installed Python and got yolo v3 running: https://github.com/reigngt09/yolov3workflow/tree/master/2_YoloV3_Execute The problem is I do not have any knowledge in Python. Is it possible to extract images and store them in a separate file while the video is running?

推荐答案

这是一种可用的方法.

  1. 从视频中提取图像
  2. 为每个图像调用检测函数
  3. 用边界框存储每个图像

下面是我使用的代码,

import cv2
import detect as dt
from darknet import Darknet
from PIL import Image

vidcap = cv2.VideoCapture('your/video/path.mp4')
success, image = vidcap.read()
count = 0

m = Darknet('your/cfg/file/path.cfg')
m.load_weights('weight/file/path.weights')
use_cuda = 1
m.cuda()

while success:
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    im_pil = Image.fromarray(image)
    im_pil = im_pil.resize((m.width, m.height))
    boxes = dt.do_detect(m, im_pil, 0.5, 0.4, use_cuda)

    result = open('your/save/file/path/frame%04d.txt'%(count), 'w')
    for i in range(len(boxes)):
        result.write(boxes[i])
    count = count + 1
    success, image = vidcap.read()
    result.close()

这篇关于yolo v3 如何提取检测到的物体的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆