佛山网站建设定制,杭州人防质监站网址,广西建设网电子证件查询,公司平台一、基本概念
1#xff0c;什么是图片#xff1f; 答#xff1a;图像是结构化存储的数据信息
2#xff0c;图像的属性 答#xff1a;1、通道数目#xff0c;2、宽与高#xff0c;3、像素数据#xff0c;4、图像类型
二、加载显示图像并保存
import cv2
import nump…一、基本概念
1什么是图片 答图像是结构化存储的数据信息
2图像的属性 答1、通道数目2、宽与高3、像素数据4、图像类型
二、加载显示图像并保存
import cv2
import numpy as npdef get_image_info(image):print(type(image))# class numpy.ndarrayprint(image.shape)# (150, 110, 3)print(image.size)# 49500 150*110*3print(image.dtype)# uint8print(np.array(image))[[[255 255 255][255 255 255][255 255 255]...[255 255 255][255 255 255][255 255 255]][[255 255 255][255 255 255][255 255 255]...[255 255 255][255 255 255][255 255 255]][[255 255 255][255 255 255][255 255 255]...[255 255 255][255 255 255][255 255 255]]...[[255 255 255][255 255 255][255 255 255]...[255 255 255][255 255 255][255 255 255]][[255 255 255][255 255 255][255 255 255]...[255 255 255][255 255 255][255 255 255]][[255 255 255][255 255 255][255 255 255]...[255 255 255][255 255 255][255 255 255]]]
src cv2.imread(G:/Juptyer_workspace/study/img/water_0.jpg)#加载图片
cv2.namedWindow(input image,cv2.WINDOW_AUTOSIZE)
cv2.imshow(input image,src)
get_image_info(src)
gray cv2.cvtColor(src,cv2.COLOR_BGR2GRAY)#彩色图片转换为灰度图
cv2.imwrite(G:/Juptyer_workspace/beyond.jpg,src)#保存该图片
cv2.imwrite(G:/Juptyer_workspace/beyond_gray.jpg,gray)#保存该图片的灰度图
cv2.waitKey(0)
cv2.destroyAllWindows()运行效果如下
三、调用电脑摄像头进行实时显示
import cv2
import numpy as npdef video_demo():capture cv2.VideoCapture(0)#0代表本地电脑自带的摄像头这里的0也可以换成视频的路径while(True):ret,frame capture.read()frame cv2.flip(frame,1)cv2.imshow(video,frame)c cv2.waitKey(50)if c 27 :#捕获回车键breaksrc cv2.imread((G:\Juptyer_workspace\study\img\water_0.jpg))
cv2.namedWindow(input image,cv2.WINDOW_AUTOSIZE)
cv2.imshow(input image,src)
video_demo(src)
cv2.waitKey(0)
cv2.destroyAllWindows()