OpenCV系列杂谈(二):图像捕获显示、摄像头捕获并显示

直接上代码:

捕获图像:

import cv2
import numpy as np


img = cv2.imread('../lena.jpg')
cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

捕获摄像头,并且播放。可以通过控制鼠标键盘空值进度。

import cv2

clicked = False
def onMouse(event, x, y, flags, param):
    global clicked
    if event == cv2.EVENT_LBUTTONDBLCLK:
        clicked = True


cameraCapture = cv2.VideoCapture(0)
cv2.namedWindow('my capture')
cv2.setMouseCallback('my capture', onMouse)

success, frame = cameraCapture.read()
while success and cv2.waitKey(1) == -1 and not clicked:
    cv2.imshow('my capture', frame)
    success, frame = cameraCapture.read()
cv2.destroyAllWindows('my capture')
cameraCapture.release()

猜你喜欢

转载自blog.csdn.net/mago2015/article/details/81370058