Skip to content

Commit a76e78f

Browse files
committedNov 28, 2013
Documentation update
1 parent 0038bb8 commit a76e78f

File tree

3 files changed

+182
-3
lines changed

3 files changed

+182
-3
lines changed
 

‎doxygen.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ EXCLUDE_SYMBOLS =
803803
# that contain example code fragments that are included (see the \include
804804
# command).
805805

806-
EXAMPLE_PATH =
806+
EXAMPLE_PATH = src
807807

808808
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
809809
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and

‎src/example.c

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#include "libuvc/libuvc.h"
2+
#include <stdio.h>
3+
4+
/* This callback function runs once per frame. Use it to perform any
5+
* quick processing you need, or have it put the frame into your application's
6+
* input queue. If this function takes too long, you'll start losing frames. */
7+
void cb(uvc_frame_t *frame, void *ptr) {
8+
uvc_frame_t *bgr;
9+
uvc_error_t ret;
10+
11+
/* We'll convert the image from YUV/JPEG to BGR, so allocate space */
12+
bgr = uvc_allocate_frame(frame->width * frame->height * 3);
13+
if (!bgr) {
14+
printf("unable to allocate bgr frame!");
15+
return;
16+
}
17+
18+
/* Do the BGR conversion */
19+
ret = uvc_any2bgr(frame, bgr);
20+
if (ret) {
21+
uvc_perror(ret, "uvc_any2bgr");
22+
uvc_free_frame(bgr);
23+
return;
24+
}
25+
26+
/* Call a user function:
27+
*
28+
* my_type *my_obj = (*my_type) ptr;
29+
* my_user_function(ptr, bgr);
30+
* my_other_function(ptr, bgr->data, bgr->width, bgr->height);
31+
*/
32+
33+
/* Call a C++ method:
34+
*
35+
* my_type *my_obj = (*my_type) ptr;
36+
* my_obj->my_func(bgr);
37+
*/
38+
39+
/* Use opencv.highgui to display the image:
40+
*
41+
* cvImg = cvCreateImageHeader(
42+
* cvSize(bgr->width, bgr->height),
43+
* IPL_DEPTH_8U,
44+
* 3);
45+
*
46+
* cvSetData(cvImg, bgr->data, bgr->width * 3);
47+
*
48+
* cvNamedWindow("Test", CV_WINDOW_AUTOSIZE);
49+
* cvShowImage("Test", cvImg);
50+
* cvWaitKey(10);
51+
*
52+
* cvReleaseImageHeader(&cvImg);
53+
*/
54+
55+
uvc_free_frame(bgr);
56+
}
57+
58+
int main(int argc, char **argv) {
59+
uvc_context_t *ctx;
60+
uvc_device_t *dev;
61+
uvc_device_handle_t *devh;
62+
uvc_stream_ctrl_t ctrl;
63+
uvc_error_t res;
64+
65+
/* Initialize a UVC service context. Libuvc will set up its own libusb
66+
* context. Replace NULL with a libusb_context pointer to run libuvc
67+
* from an existing libusb context. */
68+
res = uvc_init(&ctx, NULL);
69+
70+
if (res < 0) {
71+
uvc_perror(res, "uvc_init");
72+
return res;
73+
}
74+
75+
puts("UVC initialized");
76+
77+
/* Locates the first attached UVC device, stores in dev */
78+
res = uvc_find_device(
79+
ctx, &dev,
80+
0, 0, NULL); /* filter devices: vendor_id, product_id, "serial_num" */
81+
82+
if (res < 0) {
83+
uvc_perror(res, "uvc_find_device"); /* no devices found */
84+
} else {
85+
puts("Device found");
86+
87+
/* Try to open the device: requires exclusive access */
88+
res = uvc_open(dev, &devh);
89+
90+
if (res < 0) {
91+
uvc_perror(res, "uvc_open"); /* unable to open device */
92+
} else {
93+
puts("Device opened");
94+
95+
/* Print out a message containing all the information that libuvc
96+
* knows about the device */
97+
uvc_print_diag(devh, stderr);
98+
99+
/* Try to negotiate a 640x480 30 fps YUYV stream profile */
100+
res = uvc_get_stream_ctrl_format_size(
101+
devh, &ctrl, /* result stored in ctrl */
102+
UVC_COLOR_FORMAT_YUYV, /* YUV 422, aka YUV 4:2:2. try _COMPRESSED */
103+
640, 480, 30 /* width, height, fps */
104+
);
105+
106+
/* Print out the result */
107+
uvc_print_stream_ctrl(&ctrl, stderr);
108+
109+
if (res < 0) {
110+
uvc_perror(res, "get_mode"); /* device doesn't provide a matching stream */
111+
} else {
112+
/* Start the video stream in isochronous mode. The library will
113+
* call user function cb: cb(frame, (void*) 12345)
114+
*/
115+
res = uvc_start_iso_streaming(devh, &ctrl, cb, 12345);
116+
117+
if (res < 0) {
118+
uvc_perror(res, "start_streaming"); /* unable to start stream */
119+
} else {
120+
puts("Streaming...");
121+
122+
uvc_set_ae_mode(devh, 1); /* e.g., turn on auto exposure */
123+
124+
sleep(10); /* stream for 10 seconds */
125+
126+
/* End the stream. Blocks until last callback is serviced */
127+
uvc_stop_streaming(devh);
128+
puts("Done streaming.");
129+
}
130+
}
131+
132+
/* Release our handle on the device */
133+
uvc_close(devh);
134+
puts("Device closed");
135+
}
136+
137+
/* Release the device descriptor */
138+
uvc_unref_device(dev);
139+
}
140+
141+
/* Close the UVC context. This closes and cleans up any existing device handles,
142+
* and it closes the libusb context if one was not provided. */
143+
uvc_exit(ctx);
144+
puts("UVC exited");
145+
146+
return 0;
147+
}
148+

‎src/init.c

+33-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,43 @@
3232
* POSSIBILITY OF SUCH DAMAGE.
3333
*********************************************************************/
3434
/**
35-
\mainpage
36-
\htmlinclude manifest.html
35+
\mainpage libuvc: a cross-platform library for USB video devices
3736
3837
\b libuvc is a library that supports enumeration, control and streaming
3938
for USB Video Class (UVC) devices, such as consumer webcams.
4039
40+
\section features Features
41+
\li Asynchronous video streaming (device to host) in isochronous mode
42+
\li Synchronous streaming API (but only isochronous streaming is available)
43+
\li Read/write access to standard device settings
44+
\li Conversion between various RGB and YUV formats
45+
\li Tested on Mac and Linux, portable to Windows and some BSDs
46+
47+
\section roadmap Roadmap
48+
\li Bulk-mode image capture
49+
\li One-shot image capture
50+
\li Improved support for standard settings
51+
\li Support for "extended" (vendor-defined) settings
52+
53+
\section misc Misc.
54+
\p The source code can be found at https://github.com/ktossell/libuvc. To build
55+
the library, install <a href="http://libusb.org/">libusb</a> 1.0+ and run:
56+
57+
\code
58+
$ git clone https://github.com/ktossell/libuvc.git
59+
$ cd libuvc
60+
$ mkdir build
61+
$ cd build
62+
$ cmake -DCMAKE_BUILD_TYPE=Release ..
63+
$ make && make install
64+
\endcode
65+
66+
\section Example
67+
In this example, libuvc is used to acquire images in a 30 fps, 640x480
68+
YUV stream from a UVC device such as a standard webcam.
69+
70+
\include example.c
71+
4172
*/
4273

4374
/**

0 commit comments

Comments
 (0)
Please sign in to comment.