cv预测脚本
Posted littlepage
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于cv预测脚本的主要内容,如果未能解决你的问题,请参考以下文章