<
>

基于python-yolo的批量截图

2020-06-28 09:42:52 来源:易采站长站 作者:易采站长站整理


del draw

if len(out_boxes)!=0:
count = count+1
print(count)

end = timer()
print(end - start)
return image

def close_session(self):
self.sess.close()

def detect_video(yolo, video_path, output_path=""):
import cv2
vid = cv2.VideoCapture(video_path)
if not vid.isOpened():
raise IOError("Couldn't open webcam or video")
video_FourCC = int(vid.get(cv2.CAP_PROP_FOURCC))
video_fps = vid.get(cv2.CAP_PROP_FPS)
video_size = (int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)))
isOutput = True if output_path != "" else False
if isOutput:
print("!!! TYPE:", type(output_path), type(video_FourCC), type(video_fps), type(video_size))
out = cv2.VideoWriter(output_path, video_FourCC, video_fps, video_size)
accum_time = 0
curr_fps = 0
fps = "FPS: ??"
prev_time = timer()
while True:
return_value, frame = vid.read()
image = Image.fromarray(frame)
image = yolo.detect_image(image)
result = np.asarray(image)
curr_time = timer()
exec_time = curr_time - prev_time
prev_time = curr_time
accum_time = accum_time + exec_time
curr_fps = curr_fps + 1
if accum_time > 1:
accum_time = accum_time - 1
fps = "FPS: " + str(curr_fps)
curr_fps = 0
cv2.putText(result, text=fps, org=(3, 15), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
fontScale=0.50, color=(255, 0, 0), thickness=2)
cv2.namedWindow("result", cv2.WINDOW_NORMAL)
cv2.imshow("result", result)
if isOutput:
out.write(result)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
yolo.close_session()

def detect_list_image(dir,yolo):
for filename in os.listdir(dir):
if filename.endswith('jpg') or filename.endswith('png') or filename.endswith('JPG') :
filepath = dir+'/'+filename
image = Image.open(filepath)
image = image.convert('RGB')
image = yolo.detect_image(image)
save_name = 'result/'+filename
image.save(save_name)
if __name__ == '__main__':
dir = r'D:/tensorflow-yolo3/VOCdevkit/VOC2007/JPEGImages/xing'
detect_list_image(dir,YOLO())

# -*- coding: utf-8 -*-
"""
Class definition of YOLO_v3 style detection model on image_tie and video
"""

import colorsys
import os
from timeit import default_timer as timer
import cv2
import numpy as np
from keras import backend as K
from keras.models import load_model
from keras.layers import Input
from PIL import Image, ImageFont, ImageDraw

暂时禁止评论

微信扫一扫

易采站长站微信账号