【pytorch】pytorch-yolov3拍照并保存,进行检测后遍历所有图片并显示图片

参看摄像头参数:

v4l2-ctl -d /dev/video0 --all
安装numpy:
sudo apt-get install python-numpy
下载onnx
pip install onnx
效果图:
在这里插入图片描述

拍照部分:


# url = 'http://192.168.1.108:8080/video'

i=0

# cap = cv2.VideoCapture(url)
cap = cv2.VideoCapture(0)

array_of_img = []
start = time.time()
directory_name=r'output1'
for i in range(10):

    

    # Capture frame-by-frame

    ret, frame = cap.read()

    # Display the resulting frame

    cv2.imshow('frame'+str(i),frame)
    cv2.waitKey(0)
    #time.sleep(10);

    end = time.time()

    cv2.imwrite('/home/heziyi/桌面/PyTorch-YOLOv3/data/custom/dd2/'+str(i)+".jpg",frame)

显示部分:

from __future__ import division



from models import *

from utils.utils import *

from utils.datasets import *

from utils.augmentations import *

from utils.transforms import *



import os

import sys

import time

import datetime

import argparse



from PIL import Image



import torch

import torchvision.transforms as transforms

from torch.utils.data import DataLoader

from torchvision import datasets

from torch.autograd import Variable



import matplotlib.pyplot as plt

import matplotlib.patches as patches

from matplotlib.ticker import NullLocator

import time

from time import strftime

import cv2
array_of_img = []
start = time.time()
i=0
directory_name=r'output1'
if __name__ == "__main__":
    for filename in os.listdir(directory_name):
        i=i+1
        #print(filename) #just for test
        #img is used to store the image data 
        img = cv2.imread(directory_name + "/" + filename)
        array_of_img.append(img)
        #print(img)
        cv2.imshow(str(i),img)
        cv2.waitKey(0)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值