2
我想将USB摄像头连接到嵌入式设备。我的设备操作系统是嵌入式Linux并支持USB主机。我可以轻松读取和写入USB端口,但我不知道如何从相机捕捉图像。有没有USB摄像头的标准协议,我可以捕捉图像?USB摄像头协议
我想将USB摄像头连接到嵌入式设备。我的设备操作系统是嵌入式Linux并支持USB主机。我可以轻松读取和写入USB端口,但我不知道如何从相机捕捉图像。有没有USB摄像头的标准协议,我可以捕捉图像?USB摄像头协议
支持此功能的大多数相机使用Picture Transfer Protocol (PTP)。在Linux中,通过libgphoto2支持很多相机。
您可以使用像列出连接设备:
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);
(从libgphoto2-2.4.11 /例子/ autodetect.c两者)
看来libgphoto2是一个很大的图书馆。我需要一个简单的方法来自己使用相机。 – 2012-04-04 09:34:07
@MirMiladHosseiny在这种情况下,您可能想查看[ptpfs](http://www.dankulp.com/ptpfs/)的源代码,它可以直接在用户空间中进行所有USB通话。 – Flexo 2012-04-04 09:36:51