【问题标题】:Analyzing camera feed under OSX在 OSX 下分析摄像头馈送
【发布时间】:2011-02-09 16:20:34
【问题描述】:

我正在寻找一种在 OSX 下以编程方式分析来自外部 USB 网络摄像头的视频源的方法。

因为在我现在有点迷失从哪里开始之前,我还没有做过任何这样的低级编程。

如何访问网络摄像头源并获取图像数据以进行进一步处理? 在这一点上,我只是想了解基本概念,而不是寻找特定于语言的解决方案。 任何示例代码都将受到高度赞赏。

如果有人能指出我正确的方向并帮助我开始,我将不胜感激。

非常感谢您!

托马斯

【问题讨论】:

    标签: macos video webcam feed


    【解决方案1】:

    使用OpenCV。

    如果您正在寻找显示网络摄像头图像的代码示例,请查看我之前关于此主题的答案。它将视频源转换为灰度并将它们显示在窗口上:

    OpenCV 2.1: Runtime error

    如果您只想显示框架,则将 else 块替换为:

    else
    {
        cvShowImage("Colored video", color_frame);
    }
    

    如果您正在徘徊如何操作帧的像素:

    int width = color_frame->width; 
    int height = color_frame->height;
    int bpp = color_frame->nChannels; 
    for (int i=0; i < width*height*bpp; i+=bpp) 
    {
      if (!(i % (width*bpp))) // print empty line for better readability
          std::cout << std::endl;
    
      std::cout << std::dec << "R:" << (int) color_frame->imageData[i] <<  
                              " G:" << (int) color_frame->imageData[i+1] <<  
                              " B:" << (int) color_frame->imageData[i+2] << " "; 
    }
    

    【讨论】:

    • 我仍然在我的 Mac 上使用 OpenCV 2.1(32 位)。我不知道该代码是否仍然适用于最新版本的 OpenCV。
    • 非常感谢您将我指向 OpenCV,这正是我需要的起点!
    • @Thomas 当然。如果它回答了您的问题,请不要忘记尽可能接受我的帖子。
    【解决方案2】:

    要快速访问网络摄像头和处理像素数据,您可以使用 Processing 和 Video library - 最简单的开始方法是查看与 IDE 捆绑的示例。

    Processing 是一种基于 java 的可视化语言,易于学习和使用,适用于 WIndows、MacOSX 和 Linux。我发现网络摄像头在我的 MacBook 上开箱即用。

    这是一个示例脚本(基于捆绑在 IDE 中的示例),它加载网络摄像头提要并以灰度呈现像素。

    
    import processing.video.*;
    
    int numPixels;
    Capture video;
    
    void setup() {
      // Change size to 320 x 240 if too slow at 640 x 480
      size(640, 480, P2D); 
    
      video = new Capture(this, width, height, 24);
      numPixels = video.width * video.height;
      // Make the pixels[] array available for direct manipulation
      loadPixels();
    }
    
    void draw() {
      if (video.available()) {
        video.read(); // Read a new video frame
        video.loadPixels(); // Make the pixels of video available
        for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame...
          // Make all the pixels grey if mouse is pressed
          if (mousePressed) {
            float greyVal = brightness(video.pixels[i]);
            pixels[i] = color(greyVal);
          } else {
            // If mouse not pressed, show normal video
            pixels[i] = video.pixels[i];
          }
        }
        updatePixels(); // Notify that the pixels[] array has changed
      }
    }
    

    此外,还有一个很棒的interface to OpenCV,可用于边缘检测等。

    【讨论】:

    • 太好了,我喜欢这种处理方式。它有一堆例子
    猜你喜欢
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多