开发者

Most efficient way to capture and send images from a webcam in a network

开发者 https://www.devze.com 2023-02-08 07:04 出处:网络
I am writing a simple videophone ( for study ) and I would to know what APIs I have to use to capture and send images from a webcam in a network.

I am writing a simple videophone ( for study ) and I would to know what APIs I have to use to capture and send images from a webcam in a network.

P.s. I wouldn't use complex library l开发者_C百科ike OpenCV.


You can use Windows Image Acquisition (WIA) or/and DirectShow. Another good alternative is Microsoft Media Foundation(chapter on capturing video).

Mind you that this are cumbersome apis which make this no easy task and you might end up better by using OpenCV.

As for the network part, that's up to your design and preference.


I am just completing a similar task, I have spent days looking at the various tools/libraries.

DirectShow is the default API for windows, however it's complex for simple tasks. OpenCV is lagging in its device support and videoInput (plugin/addon) improves OpenCV.

I was able to get a simple display up and running:

http://www.aishack.in/2010/03/capturing-images-with-directx/

Using the videoInput library and OpenCV:

http://muonics.net/school/spring05/videoInput/

OpenCV may look complex, however as the first link demonstrates its only a page of code:

#include "stdafx.h"
#include "videoInput.h"
#include "cv.h"
#include "highgui.h"

int main()
{
    videoInput VI;
    int numDevices = VI.listDevices();
    int device1= 0;
    VI.setupDevice(device1);
    int width = VI.getWidth(device1);
    int height = VI.getHeight(device1);
    IplImage* image= cvCreateImage(cvSize(width, height), 8, 3);
    unsigned char* yourBuffer = new unsigned char[VI.getSize(device1)];
    cvNamedWindow("test");
    while(1)
    {
        VI.getPixels(device1, yourBuffer, false, false);
        image->imageData = (char*)yourBuffer;
        cvConvertImage(image, image, CV_CVTIMG_FLIP);
        cvShowImage("test", image);
        if(cvWaitKey(15)==27) break;
    }

    VI.stopDevice(device1);
    cvDestroyWindow("test");
    cvReleaseImage(&image);

    return 0;
}

The videoInput.h is the documentation you'll need for getting you up and running, from there out you can read the OpenCV documentation for more advanced functions. In the above example you'll want to take "image" and pipe that over a network somehow. Which is down to your communications protocol.


typical approach for Windows: use DirectShow to capture video from cam, use RTP protocol (over UDP) for real-time streaming, maybe with help of live555 library.

DirectShow way: Implement renderer filter that streams audio/video to the network and source filter that receives audio/video from the network. Data flow:

web-cam source filter -> your renderer filter -> [network] -> your source filter -> video renderer filter
                                                                                 -> audio renderer filter

Skype uses DirectShow for capturing and DirectX for drawing. they use proprietery network protocol for security (I doubt you need something like this)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号