Navigation

Operators and Keywords

Function List:

C++ API

Function File: [img, seq, ts, tc] = getsnapshot (vi, [preview])

Get a snapshot from a videoinput object buffer. Streaming has to be enabled before calling getsnapshot. If preview==true the captured image is also shown in a separate FLTK window.

img

Captured image. The type and size of img depends on the VideoFormat property of vi. H and W below refers to the height and width returned from get(VI, "VideoResolution").

RGB3, RGB24

HxWx3 uint8 matrix with RGB values

YUYV, YUV422

scalar struct with fieldnames Y, Cb and Cr. The horizontal resolution of Cb and Cr is half the horizontal resolution of Y.

YV12, YVU420, YU12, YUV420

scalar struct with fieldnames Y, Cb and Cr. The horizontal and vertical resolution of Cb and Cr is half the resolution of Y.

MJPG, MJPEG

uint8 row vector with compressed MJPEG data. The length may vary from frame to frame due to compression. You can save this as JPEG (add a huffman table) with

    set (obj, "VideoFormat", "MJPG")
    start (obj)
    img = getsnapshot (obj);
    save_mjpeg_as_jpg ("capture.jpg", img);
seq

Set by the driver, counting the frames (not fields!) in sequence.

struct ts

For input streams this is time when the first data byte was captured, as returned by the clock_gettime() function for the relevant clock id.

tv_sec

seconds

tv_usec

microseconds

struct tc

Timecode, see http://linuxtv.org/downloads/v4l-dvb-apis/buffer.html#v4l2-timecode

See also: @videoinput/start, @videoinput/preview.

Demonstration 1

The following code

 obj = videoinput ("v4l2", __test__device__);
 # see http://www.linuxtv.org/downloads/v4l-dvb-apis/V4L2-PIX-FMT-YUYV.html
 set(obj,"VideoFormat","YUYV")
 start(obj)
 img = getsnapshot(obj);
 tmp = cat (3, img.Y, kron(img.Cb, [1 1]), kron(img.Cr, [1 1]));
 # convert to RGB with octave-forge image function ycbcr2rgb
 pkg load image
 rgb = ycbcr2rgb (tmp, "709");
 image(rgb)
 title ("YUYV, Standard 709")
 stop(obj)

Produces the following figure

Figure 1

Package: image-acquisition