zoukankan      html  css  js  c++  java
  • 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() 
    

      

  • 相关阅读:
    事理学神器PDCA
    单元测试
    web框架学习路线
    编译器实现(三)
    markdown test
    设计模式
    编译器实现(二)
    编译器实现(一)
    操作系统结构
    emacs配置笔记(windows10)
  • 原文地址:https://www.cnblogs.com/xtmp/p/14027963.html
Copyright © 2011-2022 走看看