【问题标题】:USB Camera ProtocolUSB 摄像头协议
【发布时间】:2012-04-17 23:33:00
【问题描述】:

我想将 USB 摄像头连接到嵌入式设备。我的设备操作系统是嵌入式 Linux 并支持 USB 主机。我可以轻松地读取和写入 USB 端口,但我不知道如何从相机捕获图像。是否有任何标准的 USB 摄像头协议可以捕获图像?

【问题讨论】:

    标签: camera embedded usb webcam


    【解决方案1】:

    大多数支持此功能的相机使用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/examples/autodetect.c)

    【讨论】:

    • 看来libgphoto2是个大库。我需要一个简单的方法来自己使用相机。
    • @MirMiladHosseiny 在这种情况下,您可能需要查看 ptpfs 的源代码,它直接在用户空间中进行所有 USB 通信。
    猜你喜欢
    • 1970-01-01
    • 2012-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-17
    • 2017-05-12
    相关资源
    最近更新 更多