2012-04-04 3 views
2

USB 카메라를 내장 장치에 연결하고 싶습니다. 내 장치 OS는 Linux에 내장되어 있으며 USB 호스트를 지원합니다. USB 포트로 쉽게 읽고 쓸 수 있지만 카메라에서 이미지를 캡처하는 방법을 모르겠습니다. USB 카메라에 이미지를 캡처 할 수있는 표준 프로토콜이 있습니까?USB 카메라 프로토콜

답변

2

이 기능을 지원하는 대부분의 카메라는 Picture Transfer Protocol (PTP)입니다. 리눅스에서는 많은 카메라에 대해 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에서 촬영)

+0

그 libgphoto2 큰 라이브러리 것 같다. 나는 자신의 카메라를 사용하는 간단한 방법이 필요합니다. –

+0

@MirMiladHosseiny이 경우 사용자 공간에서 직접 말하는 모든 USB를 수행하는 [ptpfs] (http://www.dankulp.com/ptpfs/)의 소스를보고 싶을 수 있습니다. – Flexo