Reputation: 2857
I want to connect a USB camera to an embedded device. My device OS is embedded Linux and supports USB Host. I can read and write to USB port easily, but I don't know how I can capture an image from camera. Is there any standard protocol for USB camera that I can capture image?
Upvotes: 2
Views: 3400
Reputation: 88711
Most cameras that support this use Picture Transfer Protocol (PTP). In Linux there is support for this via libgphoto2 for a lot of cameras.
You can list connected devices using something like:
CameraList *xlist = NULL;
ret = gp_list_new (&xlist);
if (ret < GP_OK) goto out;
if (!portinfolist) {
/* Load all the port drivers we have... */
ret = gp_port_info_list_new (&portinfolist);
if (ret < GP_OK) goto out;
ret = gp_port_info_list_load (portinfolist);
if (ret < 0) goto out;
ret = gp_port_info_list_count (portinfolist);
if (ret < 0) goto out;
}
/* Load all the camera drivers we have... */
ret = gp_abilities_list_new (&abilities);
if (ret < GP_OK) goto out;
ret = gp_abilities_list_load (abilities, context);
if (ret < GP_OK) goto out;
/* ... and autodetect the currently attached cameras. */
ret = gp_abilities_list_detect (abilities, portinfolist, xlist, context);
if (ret < GP_OK) goto out;
/* Filter out the "usb:" entry */
ret = gp_list_count (xlist);
if (ret < GP_OK) goto out;
for (i=0;i<ret;i++) {
const char *name, *value;
gp_list_get_name (xlist, i, &name);
gp_list_get_value (xlist, i, &value);
if (!strcmp ("usb:",value)) continue;
gp_list_append (list, name, value);
}
out:
gp_list_free (xlist);
return gp_list_count(list);
(Taken from libgphoto2-2.4.11/examples/autodetect.c)
Upvotes: 2