用于计算机视觉和图像处理

天问 e98b91f3be Update 'README.md' 8 months ago
README.md e98b91f3be Update 'README.md' 8 months ago

README.md

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()