2011-02-09 75 views
2

我正在寻找一种方法来编程分析从OSX下的外部USB摄像头视频饲料。分析摄像头饲料在OSX下

因为我没有做过这样的低级编程,所以在我目前有点迷失在哪里开始。

如何访问网络摄像头供稿并获取图像数据然后进一步处理? 在这一点上,我只是想了解基本概念,而不是寻找语言特定的解决方案。任何示例代码将不胜感激。

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

非常感谢您提前!

Thomas

回答

1

使用OpenCV

如果您正在寻找一个代码示例来显示网络摄像头图像,请查看我之前对此主题的回答。它把视频馈送为灰度,并显示一个窗口:

OpenCV 2.1: Runtime error

如果你只是想显示的帧,然后通过这个替换其他块:

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] << " "; 
} 
+0

我还是用的OpenCV 2.1(32位)。我不知道该代码是否仍然适用于最新版本的OpenCV。 – karlphillip 2011-02-09 16:36:22

+0

非常感谢您指点我OpenCV,这只是我需要的起点! – 2011-02-09 16:51:33

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可用于在我的Mac边缘检测等