Python 显示图片和调用摄像头

'''读取并显示图片  
import cv2 
img = cv2.imread("D:/python/a.jpg") 
cv2.namedWindow("Image") 
cv2.imshow("Image", img) 
cv2.waitKey (0)
'''
import cv2
import numpy as np
import pickle
  
cap = cv2.VideoCapture(0 + cv2.CAP_DSHOW)
#python cv2调用摄像头时出现python已停止工作错误:cap = cv2.VideoCapture(0 + cv2.CAP_DSHOW) 即可
#现在网上都是一个版本,哪怕教材也是这样
  
while True:
  ret,frame = cap.read()
  # Our operations on the frame come here
  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  # Display the resulting frame
  cv2.imshow('frame',gray)
  if cv2.waitKey(1) & 0xFF == ord('q'):
    break
  
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows() 

  

posted @ 2020-11-23 23:28  虚幻的街景  阅读(539)  评论(1编辑  收藏  举报