在OSX下分析摄像机馈送

时间:2011-02-09 16:20:35

标签: macos video webcam feed

我正在寻找一种方法,以编程方式分析OSX下外部usb网络摄像头的视频输入。

由于我之前没有做过任何类似的低级编程,所以我目前还不知道从哪里开始。

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

如果有人能指出我正确的方向并帮助我开始,我会非常感激。

非常感谢你!

托马斯

2 个答案:

答案 0 :(得分: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] << " "; 
}

答案 1 :(得分:1)

为了快速访问网络摄像头和处理像素数据,您可以将ProcessingVideo 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可以用于边缘检测等。

相关问题