import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
def photo_save():
capture = cv.VideoCapture(0, cv.CAP_DSHOW)
while True:
ret, frame = capture.read() #ret=return,frame是视频的每一帧
frame = cv.flip(frame, 1) #镜像倒转 1是正像-1是反像
if ret:
cv.imshow("video", frame) # 显示图像的每一帧
if cv.waitKey(1) & 0xFF == ord('q'):
cv.imwrite("D:/summer/test.png", frame)
file_name = "xieyang.jpg"
cv.imwrite(file_name, frame)
break
def binary(image): #对图像进行二值化处理
gray = cv.cvtColor(image, cv.COLOR_RGB2GRAY)
ret, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV | cv.THRESH_OTSU) # 进行图像二值化
cv.imshow("binary", binary)
def image_hist(image): #展示图像的直方图和灰度图
image =
opencv+python实现调用摄像头进行拍照保存,并对图像进行置灰处理
最新推荐文章于 2023-02-27 13:39:04 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)