cv预测脚本

opencv安装,之后可以装载自己的模型进行视频预测

pip install opencv-python

cv预测转视频脚本

# from keras.layers import Input
from frcnn import FRCNN
from PIL import Image
import numpy as np
import cv2

frcnn = FRCNN()
# 调用摄像头
capture=cv2.VideoCapture('/Users/steveyu/PycharmProjects/faster-rcnn-keras-master/VOCdevkit/VOC2007/承装配电1.mp4')
size = (int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)),
        int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fps = capture.get(cv2.CAP_PROP_FPS)
out = cv2.VideoWriter("3.avi", cv2.VideoWriter_fourcc(*'DIVX'), fps, size)
while(True):
    # 读取某一帧
    ref,frame=capture.read()
    # 格式转变,BGRtoRGB
    frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
    # 转变成Image
    frame = Image.fromarray(np.uint8(frame))

    # 进行检测
    frame = np.array(frcnn.detect_image(frame))
    # RGBtoBGR满足opencv显示格式
    frame = cv2.cvtColor(frame,cv2.COLOR_RGB2BGR)
    out.write(frame)
    c= cv2.waitKey(1) & 0xff

cv预测显示脚本

from keras.layers import Input
from frcnn import FRCNN
from PIL import Image
import numpy as np
import cv2

frcnn = FRCNN()

# 调用摄像头
capture=cv2.VideoCapture('承装配电.mp4')
while(True):
    # 读取某一帧
    ref,frame=capture.read()
    # 格式转变,BGRtoRGB
    frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
    # 转变成Image
    frame = Image.fromarray(np.uint8(frame))

    # 进行检测
    frame = np.array(frcnn.detect_image(frame))
    # RGBtoBGR满足opencv显示格式
    frame = cv2.cvtColor(frame,cv2.COLOR_RGB2BGR)
    cv2.imshow("承装配电",frame)
    c= cv2.waitKey(1) & 0xff
    if c==27:
        capture.release()
        break

 

posted @ 2020-05-13 16:07  SteveYu  阅读(225)  评论(0编辑  收藏  举报