基于Python OpenCV加载视频文件,显示,并绘制自定义文字

来源:互联网 发布:专线网络 编辑:程序博客网 时间:2024/06/05 19:07

最近在做一个关于视觉项目,使用到Python版本的OpenCV,由于之前都是使用OpenCV的C++版本接口,对Python的语法不熟悉,因此,这里把基于Python语言的实现过程记录下来。

 

代码实现的功能就是加载一个视频文件,创建窗口进行显示,并在图像窗口上绘制自定义文字。

 

先贴一个运行图:


全部的实现代码:

'''Author:xiaoufeiDate:2017/10/17Description: read in a video file, create a display window,and draw user defined text on the windowFile: testVideo.py'''import numpy as npimport cv2if __name__ == "__main__":    #step1: load in the video file    videoCapture=cv2.VideoCapture('test.MOV')        #step2:get a frame    sucess,frame=videoCapture.read()        #step3:get frames in a loop and do process     while(sucess):        sucess,frame=videoCapture.read()        displayImg=cv2.resize(frame,(1024,768)) #resize it to (1024,768)        cv2.putText(displayImg,"Hello World!",(400,50),cv2.FONT_HERSHEY_PLAIN,2.0,(0,0,255),2)        cv2.namedWindow('test Video')            cv2.imshow("test Video",displayImg)        keycode=cv2.waitKey(1)        if keycode==27:            cv2.destroyWindow('test Video')            videoCapture.release()            break

附:我的开发环境是Ubuntu16.04+OpenCV3.1.0+Python2.7.12



阅读全文
0 0
原创粉丝点击