cv(一)

1.环境搭建

  pip install opencv-python

  pip install opencv-contrib-python(cv拓展库)

  pip install pytesseract(goole开源ocr引擎)

2.读图片

1 import cv2 
2 src = cv.imread('')
3 cv2.nameWindow('inpyt image', cv.WINDOW_AUTOSIZE)
4 cv2.waitkey(0)
5 cv2.destoryAllWindows()
6 print('Hi, Python')
imread

 3.加载与保存

 1 import cv2 as cv
 2 import numpy as np
 3 
 4 
 5 def video_demo():
 6     capture = cv.VideoCapture(0)  # 读视频
 7     while(True):
 8         ret, frame = capture.read()
 9         frame = cv.flip(frame, 1)  # 画面颠倒,控制左右上下变换
10         cv.imshow('video', frame)
11         c = cv.waitKey(50)
12         if c == 27:
13             break
14             
15             
16 def get_image_info(image):
17     print(type(image))
18     print(image.shape)
19     print(image.size)
20     print(image.dtype)
21     pixel_data = np.array(image)
22     print(pixel_data)
23 
24 
25 print('--------Hello Python------------')
26 src = cv.imread('')  # 读图
27 get_image_info(src)
28 gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)  # 转换灰度图像
29 cv.imwrite('ss.png', gray)  # 保存
30 video_demo()  
read video

 

posted @ 2020-06-13 09:07  liang哥哥  阅读(183)  评论(0)    收藏  举报