码迷,mamicode.com
首页 > 其他好文 > 详细

cv预测脚本

时间:2020-05-13 17:11:17      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:array   cts   oca   charm   char   install   视频   break   ima   

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

 

cv预测脚本

标签:array   cts   oca   charm   char   install   视频   break   ima   

原文地址:https://www.cnblogs.com/littlepage/p/12883002.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!