在进行python图像处理学习当中无法通过代码运行调用摄像头,代码文字被标记,但是能运行不报错。
- ```python
import cv2
import cv2 as cv
import numpy as np
def video_demo():
capture = cv.VideoCapture(0)
while True:
ret, frame = capture.read()
frame = cv.flip(frame, 1)
cv.imshow("video", frame)
c = cv.waitKey(50)
if c == 27:
break
def get_image_info(image):
print(type(image))
print(image.shape) # 高,宽,通道
print(image.size) # 像素数据(高宽通道数)
print(image.dtype) # 每个通道所占的位数
pixel_data = np.array(image)
print(pixel_data)
print("--------- Hello Python ---------")
src = cv.imread("D:/1.jpg")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)
get_image_info(src) # 调用api
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
cv.imwrite("D:/result.png", gray)
cv.waitKey(0)
cv.destroyAllWindows()
```