一、打开关闭图片
import cv2
def main():
print("hello")
cv2.namedWindow("imgWindow",cv2.WINDOW_NORMAL)
img = cv2.imread("D:\\myfile\\project\\vision\\img\\lena.bmp")
cv2.imshow("imgWindow",img)
while True:
key = cv2.waitKey(0)
if(key & 0xff == ord('q')):
break
elif(key & 0xff == ord('s')):
cv2.imwrite("D:\\myfile\\project\\vision\\img\\lena.png",img)
cv2.destroyAllWindows()
exit()
if __name__ == '__main__':
main()
二、从多媒体文件中获取视频帧
import cv2
def main():
print("hello")
cv2.namedWindow("videoWindow",cv2.WINDOW_NORMAL)
cv2.resizeWindow("videoWindow",640,480)
video = cv2.VideoCapture("D:\\myfile\\project\\vision\\video\\speed.mkv")
while True:
ret,frame = video.read()
cv2.imshow("videoWindow",frame)
key = cv2.waitKey(40)
if(key & 0xff == ord('q')):
break
video.release()
cv2.destroyAllWindows()
exit()
if __name__ == '__main__':
main()