标签: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
标签:array cts oca charm char install 视频 break ima
原文地址:https://www.cnblogs.com/littlepage/p/12883002.html