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() 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM