YOLO camera

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qiqzhang/article/details/82981610
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()

猜你喜欢

转载自blog.csdn.net/qiqzhang/article/details/82981610
今日推荐