YOLO camera

import sys
import argparse
from yolo import YOLO, detect_video
from PIL import Image
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
import os
import time
from timeit import default_timer as timer
####ImageDraw.py changed  #/home/xxy/anaconda3/lib/python3.6/site-packages/PIL/ImageDraw.py
import cv2


capture = cv2.VideoCapture(0)
time = 0
def detect_img(yolo):
    global time
#    while True:
    start = timer()
#    path = '/home/zq/Downloads/keras-yolo3/VOCdevkit/VOC2007/JPEGImages'
#    save = '/home/zq/Downloads/keras-yolo3/VOCdetect/VOC2007/JPEGImages'
    path = '/home/zq/Desktop/camera_save/'
    save = '/home/zq/Desktop/camera_test/'
    while(True):
        ret, frame = capture.read()  # 读取视频帧
#        frame_1 = cv2.flip(frame, 1) # 将视频帧切片
        time = time+1
        cv2.imshow("video", frame) # 显示
        cv2.imwrite(path+str(time)+".jpg",frame)
        
        cv2.waitKey(5) # 等待
        image = Image.open(path+str(time)+".jpg")
        r_image = yolo.detect_image(image)

        r_image.save(save+str(time)+".jpg")#baocun
        img = cv2.imread(save+str(time)+".jpg")
        cv2.namedWindow('test', flags=0)
        cv2.imshow('test', img)
#        except:
#            print(img)
#            r_image.show()
    end = timer()
    allT = (end-start)
    print("This is cost all Time",allT)
    yolo.close_session()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值