Browse Source

Update 'README.md'

天问 1 month ago
parent
commit
e98b91f3be
1 changed files with 42 additions and 1 deletions
  1. 42 1
      README.md

+ 42 - 1
README.md

@@ -1,3 +1,44 @@
 # opencv-python
 
-用于计算机视觉和图像处理
+用于计算机视觉和图像处理
+
+## Usage
+
+```
+pip install opencv-python
+
+
+import cv2
+
+# 加载图像
+image = cv2.imread('image.jpg')
+if image is not None:
+    # 将图像转换为灰度图
+    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
+    # 显示图像
+    cv2.imshow('Image', image)
+    cv2.waitKey(0)
+    cv2.destroyAllWindows()
+else:
+    print('Failed to load image.')
+
+
+# 打开摄像头
+cap = cv2.VideoCapture(0)
+
+while True:
+    # 读取视频帧
+    ret, frame = cap.read()
+
+    # 显示视频帧
+    cv2.imshow('Video', frame)
+
+    # 检测键盘输入
+    if cv2.waitKey(1) & 0xFF == ord('q'):
+        break
+
+# 释放摄像头资源
+cap.release()
+cv2.destroyAllWindows()
+
+```