canon EDSDK saving image in my PC

前端 未结 1 1085
甜味超标
甜味超标 2021-01-06 15:32

I am using EDSDK v2.13 with my EOS 50D camera. I want to save taken pictures in my host. I am using this code (c++):

    EdsOpenSession(camera);
    EdsInt32         


        
相关标签:
1条回答
  • 2021-01-06 16:24

    it doesn't work that way. After you have taken the photo you need to catch the ObjectEvent and then download the file. It works something like this:

    • Open session
    • Set SaveTo_Both or Host
    • Set Capacity
    • Subscribe to the object event with EdsSetObjectEventHandler
    • Take photo
    • The object event should fire with "inEvent" being "kEdsObjectEvent_DirItemRequestTransfer"
    • Download the data:
      • Get info with EdsGetDirectoryItemInfo where "inDirItemRef" is "inRef" from the event
      • Create file stream with EdsCreateFileStream
      • Download the data with EdsDownload (inRef from the event, size from the DirectoryItemInfo)
      • Mark as finished with EdsDownloadComplete (inRef from the event)
      • Release the data with EdsRelease (inRef from the event)
      • Release the stream with EdsRelease

    I'm sorry that I can't provide you actual code, I'm not a C++ developer. If you want I can show you some C# code though. To get more details on how the functions work, you could also check the documentation of the SDK.

    Kind regards

    Edit:

    Ok, some C++ code with help of the documentation: Note that this is how it would work in it's barest form. You should always check if err != EDS_ERR_OK. And you should call Close only after the image has been downloaded.

    void TakePhoto()
    {
        EdsError err = EDS_ERR_OK;
        EdsCameraRef camera = NULL;
        EdsCameraListRef cameraList = NULL;
        EdsUInt32 count = 0;
    
        err = EdsInitializeSDK();
        err = EdsGetCameraList(&cameraList);
        err = EdsGetChildCount(cameraList, &count);
        if (count > 0)
        {
            err = EdsGetChildAtIndex(cameraList, 0, &camera);
            cameraList = NULL;
            err = EdsSetObjectEventHandler(camera, kEdsObjectEvent_All, handleObjectEvent, NULL);
            err = EdsOpenSession(camera);
            err = EdsSendCommand(camera, kEdsCameraCommand_TakePicture, 0);
        }
    }
    
    void Close(EdsCameraRef *camera)
    {
        err = EdsCloseSession(camera);
        EdsRelease(camera);
        EdsTerminateSDK();
    }
    
    static EdsError EDSCALLBACK handleObjectEvent(EdsObjectEvent event, EdsBaseRef object, EdsVoid * context)
    {
        if (event == kEdsObjectEvent_DirItemRequestTransfer)
        {
            EdsError err = EDS_ERR_OK;
            EdsStreamRef stream = NULL;
            EdsDirectoryItemInfo dirItemInfo;
            err = EdsGetDirectoryItemInfo(object, &dirItemInfo);
            err = EdsCreateFileStream(dirItemInfo.szFileName, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
            err = EdsDownload(object, dirItemInfo.size, stream);
            err = EdsDownloadComplete(object);
            EdsRelease(stream);
            stream = NULL;
        }
        if (object) EdsRelease(object);
    }
    
    0 讨论(0)
提交回复
热议问题