小编Diw*_*kar的帖子

使用opencv在python中以灰度显示相机供稿

我一直试图以灰度显示来自笔记本电脑网络摄像头的相机提要,并且已经使用以下代码完成了该操作:

    import cv2
    import numpy as np
    clicked = False
    def onMouse(event, x, y, flags, param):
        global clicked
        if event == cv2.cv.CV_EVENT_LBUTTONUP:
            clicked = True

    cv2.namedWindow('image capture', cv2.WINDOW_NORMAL)
    cv2.setMouseCallback('image capture', onMouse)
    #initialize the camera object with VideoCapture
    camera = cv2.VideoCapture(0)
    sucess, frame = camera.read()
    cv2.imwrite('snapshot.png', frame)
    gray = cv2.imread('snapshot.png', cv2.IMREAD_GRAYSCALE)
    while sucess and cv2.waitKey(1) == -1 and not clicked:
        cv2.imwrite('snapshot.png', frame)
        gray = cv2.imread('snapshot.png', cv2.IMREAD_GRAYSCALE)
        cv2.imshow('image capture', gray)
        sucess, frame = camera.read()

    cv2.imwrite('snapshot.png', frame)
    print 'photo taken press any key …
Run Code Online (Sandbox Code Playgroud)

python opencv grayscale

0
推荐指数
1
解决办法
4147
查看次数

标签 统计

grayscale ×1

opencv ×1

python ×1