收藏:①极市开发DeepLearning ②Git使用

1、OpenCV Python 图像加载和保存

 1 __author__ = "WSX"
 2 import cv2 as cv
 3 # 这里的文件是图片或者视频
 4 def Save_File( image ):
 5     cv.imwrite("1.png", image)   #保存
 6 
 7 def get_image_info( image ):  #获取图像属性
 8     print("""
 9     图像的高宽通道:%s
10     图像的大小:%s
11     图像的位数:%s
12     图像类别:%s
13     """ %(image.shape ,image.size ,image.dtype ,type(image)))
14 
15 def Load_image_show():  #获取图像
16     src= cv.imread("1.JPG")    #src变为数组(numpy类型)
17     cv.namedWindow("Show" , cv.WINDOW_AUTOSIZE)
18     cv.imshow("Show" , src)
19     cv.waitKey(0)
20     cv.destroyAllWindows()
21     get_image_info(src)
22     Save_File(src)
23 Load_image_show()
24 
25 def Load_video_show():  #获取视频
26     video = cv.VideoCapture(0)  # 0 表示摄像头 ,
27     while (True):
28         ret, frame = video.read()  #frame为 帧
29         frame = cv.flip( frame ,1)  #镜像变换,图像正与不正
30         cv.imshow("video" ,frame)
31         c = cv.waitKey(50)
32         print( ret )
33         if c == 27: #esc退出
34             break
35 #Load_video_show()

 

posted @ 2018-06-07 16:23  WSX_1994  阅读(481)  评论(0编辑  收藏  举报