【问题标题】:Capture images in python using the camera on my laptop (color or gray scale) [closed]使用笔记本电脑上的相机(彩色或灰度)在 python 中捕获图像 [关闭]
【发布时间】:2021-12-31 05:31:04
【问题描述】:

对于我的 Mac,我想使用 Python 来捕获图像,然后将它们转换为 numpy 数组(彩色或灰度都适合我)。即使先将图像存储到磁盘,然后再通过脚本转换它们也可以。

我已经读到 cv2 很有用,我已经尝试过设置或使用它但未能成功。欢迎任何帮助,包括代码示例。

【问题讨论】:

    标签: machine-learning networking artificial-intelligence


    【解决方案1】:

    您可以使用来自https://www.geeksforgeeks.org/python-opencv-capture-video-from-camera/ 的以下代码使用 OpenCV 捕获图像:

    # import the opencv library
    import cv2
      
      
    # define a video capture object
    vid = cv2.VideoCapture(0)
      
    while(True):
          
        # Capture the video frame
        # by frame
        ret, frame = vid.read()
    
        # convert to grayscale
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
      
        # Display the resulting frame
        cv2.imshow('frame', frame)
          
        # the 'q' button is set as the
        # quitting button you may use any
        # desired button of your choice
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
      
    # After the loop release the cap object
    vid.release()
    # Destroy all the windows
    cv2.destroyAllWindows()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-30
      • 1970-01-01
      • 2023-01-03
      • 2011-02-25
      • 2021-10-06
      • 2015-11-20
      • 2011-04-25
      • 2023-01-21
      相关资源
      最近更新 更多