Esempio n. 1
0
bool tcam::save_image (CaptureDevice& g, const std::string& filename)
{

    struct data
    {
        CaptureDevice* g;
        std::string filename;
        int count;
        bool wait;
    };

    auto f = [] (MemoryBuffer* buf, void* userdata)
        {
            data* d = static_cast<data*>(userdata);

            if (d->count >= 2)
            {
                //save_jpeg(*buf, d->filename);
                d->wait = false;
            }
            else
            {
                d->count++;
            }
        };

    auto sink = std::make_shared<ImageSink>();

    data d;
    d.g = &g;
    d.filename = filename;
    d.count = 0;
    d.wait = true;

    sink->registerCallback(f, &d);

    VideoFormat v;
    v.from_string("format=RGB24,width=640,height=480,binning=0,framerate=30.000000");
    g.set_video_format(v);
    g.start_stream(sink);

    // wait until image was captured
    while(d.wait)
    {
        usleep(500);
    }
    d.g->stop_stream();

    std::cout << "Successfully saved image" << std::endl;

    return true;
}
Esempio n. 2
0
bool set_active_format (std::shared_ptr<CaptureDevice> dev, const std::string& new_format)
{
    VideoFormat v;

    bool ret = v.from_string(new_format);

    if (ret)
    {
        return dev->set_video_format(v);
    }
    else
    {
        std::cout << "Invalid string description!" << std::endl;
    }
    return false;
}