canon EDSDK saving image in my PC

亡梦爱人 提交于 2019-12-06 08:02:40

问题


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 saveTarget = kEdsSaveTo_Both;
    err = EdsSetPropertyData( camera, kEdsPropID_SaveTo, 0, 4, &saveTarget );

    EdsCapacity newCapacity = {0x7FFFFFFF, 0x1000, 1};
    err = EdsSetCapacity(camera, newCapacity);

  const char* ch_dest = "C:\\photo\\Img.jpg";
  EdsCreateFileStreamEx( ch_dest ,kEdsFileCreateDisposition_CreateNew,kEdsAccess_ReadWrite, 0);

    EdsSendCommand(camera, kEdsCameraCommand_TakePicture, 0);
    EdsCloseSession(camera);
    EdsTerminateSDK();

The camera shutter fires normally and I find the picture in the memory card of my camera but I cannot find it in my PC.

Please help.


回答1:


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);
}


来源:https://stackoverflow.com/questions/22965982/canon-edsdk-saving-image-in-my-pc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!