int getNumberOfImages(EdsCameraRef handle) { EdsVolumeRef volume; EdsGetChildAtIndex(handle, 0, &volume); EdsDirectoryItemRef dcim; EdsGetChildAtIndex(volume, 0 , &dcim); int numFiles = getNumberOfImages_sub(dcim); EdsRelease(dcim); EdsRelease(volume); return numFiles; }
EdsError CanonEDCamera::getFirstCamera(EdsCameraRef *camera) { EdsError err = EDS_ERR_OK; EdsCameraListRef cameraList = NULL; EdsUInt32 count = 0; // Get camera list err = EdsGetCameraList(&cameraList); // Get number of cameras if(err == EDS_ERR_OK) { err = EdsGetChildCount(cameraList, &count); if(count == 0) { err = EDS_ERR_DEVICE_NOT_FOUND; } } // Get first camera retrieved if(err == EDS_ERR_OK) { err = EdsGetChildAtIndex(cameraList , 0 , camera); } // Release camera list if(cameraList != NULL) { EdsRelease(cameraList); cameraList = NULL; } return err; }
CanonCamera::CanonCamera(void) { liveView = false; camID = numOfCameras; numOfCameras++; windowName = "Camera "; windowName += '1' + camID; windowName += " Window"; EdsCameraListRef cameraList = NULL; EdsGetCameraList(&cameraList); EdsUInt32 camCount = 0; EdsGetChildCount(cameraList, &camCount); if(camCount==0) { std::cout<<"No Camera Found"<<". Press Any Key to Exit."; getch(); exit(-1); } else { std::cout<<camCount<<" Camera(s) found!\n"; } EdsError err = EDS_ERR_OK; err = EdsGetChildAtIndex(cameraList , camID , &camera); //Release camera list if(cameraList != NULL) { EdsRelease(cameraList); } detectedCams=camCount; //open sesion err=EdsOpenSession(camera); if(err!=EDS_ERR_OK) { std::cout<<"Problem with Camera connection"<<". Press Any Key to Exit"; getch(); exit(-1); } }
Camera CameraList::get(const int index) { EdsCameraRef camera = nullptr; EdsError err = EdsGetChildAtIndex(list_, 0, &camera); if (EDS_ERR_OK != err) { DEBUGSTREAM << DescribeError(err) << std::endl; throw Exception(err); } Camera retval = Camera(camera); retval.Initialize(); return retval; }
IEnumerable<Camera^>^ CameraManager::GetCameraList() { EdsCameraListRef cameraHandleList; EdsUInt32 cameraCount; List<Camera^>^ cameraList = gcnew List<Camera^>(); // Iterate through the camera handles and create a new Camera wrapper for each one. ErrorCheck(EdsGetCameraList(&cameraHandleList)); ErrorCheck(EdsGetChildCount(cameraHandleList, &cameraCount)); for (int i = 0; i < (int)cameraCount; i++) { EdsCameraRef cameraHandle; ErrorCheck(EdsGetChildAtIndex(cameraHandleList, i, &cameraHandle)); cameraList->Add(gcnew Camera(cameraHandle)); } return cameraList; }
int getNumberOfImages_sub(EdsDirectoryItemRef directoryItem) { EdsUInt32 numChildren; EdsGetChildCount(directoryItem, &numChildren); EdsDirectoryItemInfo directoryItemInfo; EdsGetDirectoryItemInfo(directoryItem, &directoryItemInfo); int numFiles = 0; EdsDirectoryItemRef childItem; EdsDirectoryItemInfo childItemInfo; for (int iter = 0; iter < numChildren; ++iter) { EdsGetChildAtIndex(directoryItem, iter, &childItem); EdsGetDirectoryItemInfo(childItem, &childItemInfo); if (childItemInfo.isFolder == true) { numFiles += getNumberOfImages_sub(childItem); } else { ++numFiles; } EdsRelease(childItem); } return numFiles; }
EdsCameraRef openCamera() { EdsCameraListRef cameraList = NULL; // Get camera list EdsError err = EdsGetCameraList(&cameraList); if (err != EDS_ERR_OK) { handleErrorCode(err); } EdsUInt32 numCameras = 0; // Get number of cameras err = EdsGetChildCount(cameraList, &numCameras); if (err == EDS_ERR_OK) { handleErrorCode(err); } if (numCameras > 1) { mexWarnMsgTxt("Warning: more than one available cameras found. Multiple cameras are not well supported."); } else if (numCameras <= 0) { mexErrMsgIdAndTxt(ERROR_ID, "No available camera found."); return NULL; } EdsCameraRef handle; // Get first camera retrieved err = EdsGetChildAtIndex(cameraList , 0 , &handle); if (err != EDS_ERR_OK) { handleErrorCode(err); } // Release camera list if (cameraList != NULL) { EdsRelease(cameraList); cameraList = NULL; } // Set object event handler err = EdsSetObjectEventHandler(handle, kEdsObjectEvent_All, handleObjectEvent, NULL); if (err != EDS_ERR_OK) { handleErrorCode(err); } // Set property event handler err = EdsSetPropertyEventHandler(handle, kEdsPropertyEvent_All, handlePropertyEvent, NULL); if (err != EDS_ERR_OK) { handleErrorCode(err); } // Set camera state event handler err = EdsSetCameraStateEventHandler(handle, kEdsStateEvent_All, handleStateEvent, NULL); if (err != EDS_ERR_OK) { handleErrorCode(err); } // Open session with camera err = EdsOpenSession(handle); if (err != EDS_ERR_OK) { handleErrorCode(err); } return handle; }
//--------------------------------------------------------------------- bool CanonCameraWrapper::downloadLastImage(){ preCommand(); EdsVolumeRef theVolumeRef = NULL ; EdsDirectoryItemRef dirItemRef_DCIM = NULL; EdsDirectoryItemRef dirItemRef_Sub = NULL; EdsDirectoryItemRef dirItemRef_Image = NULL; EdsDirectoryItemInfo dirItemInfo_Image; EdsError err = EDS_ERR_OK; EdsUInt32 Count = 0; bool success = false; //get the number of memory devices err = EdsGetChildCount( theCamera, &Count ); if( Count == 0 ){ printf("Memory device not found\n"); err = EDS_ERR_DEVICE_NOT_FOUND; return false; } // Download Card No.0 contents err = EdsGetChildAtIndex( theCamera, 0, &theVolumeRef ); // if ( err == EDS_ERR_OK ){ // printf("getting volume info\n"); // //err = EdsGetVolumeInfo( theVolumeRef, &volumeInfo ) ; // } //Now lets find out how many Folders the volume has if ( err == EDS_ERR_OK ){ err = EdsGetChildCount( theVolumeRef, &Count ); if ( err == EDS_ERR_OK ){ //Lets find the folder called DCIM bool bFoundDCIM = false; for(int i = 0; i < Count; i++){ err = EdsGetChildAtIndex( theVolumeRef, i, &dirItemRef_DCIM ) ; if ( err == EDS_ERR_OK ){ EdsDirectoryItemInfo dirItemInfo; err = EdsGetDirectoryItemInfo( dirItemRef_DCIM, &dirItemInfo ); if( err == EDS_ERR_OK){ string folderName = dirItemInfo.szFileName; if( folderName == "DCIM" ){ bFoundDCIM = true; printf("Found the DCIM folder at index %i\n", i); break; } } } //we want to release the directories that don't match easyRelease(dirItemRef_DCIM); } //This is a bit silly. //Essentially we traverse into the DCIM folder, then we go into the last folder in there, then we //get the last image in last folder. if( bFoundDCIM && dirItemRef_DCIM != NULL){ //now we are going to look for the last folder in DCIM Count = 0; err = EdsGetChildCount(dirItemRef_DCIM, &Count); bool foundLastFolder = false; if( Count > 0 ){ int lastIndex = Count-1; EdsDirectoryItemInfo dirItemInfo_Sub; err = EdsGetChildAtIndex( dirItemRef_DCIM, lastIndex, &dirItemRef_Sub ) ; err = EdsGetDirectoryItemInfo( dirItemRef_Sub, &dirItemInfo_Sub); printf("Last Folder is %s \n", dirItemInfo_Sub.szFileName); EdsUInt32 jpgCount = 0; err = EdsGetChildCount(dirItemRef_Sub, &jpgCount ); if( jpgCount > 0 ){ int latestJpg = jpgCount-1; err = EdsGetChildAtIndex(dirItemRef_Sub, latestJpg, &dirItemRef_Image ) ; err = EdsGetDirectoryItemInfo(dirItemRef_Image, &dirItemInfo_Image); printf("Latest image is %s \n", dirItemInfo_Image.szFileName); success = true; }else{ printf("Error - No jpegs inside %s\n", dirItemInfo_Image.szFileName); } }else{ printf("Error - No subfolders inside DCIM!\n"); } } } } if( success ){ success = downloadImage(dirItemRef_Image); } easyRelease(theVolumeRef); easyRelease(dirItemRef_DCIM); easyRelease(dirItemRef_Sub); easyRelease(dirItemRef_Image); postCommand(); return success; }
//--------------------------------------------------------------------- bool CanonCameraWrapper::setup(int cameraID){ if( theCamera != NULL || theCameraList != NULL){ destroy(); } EdsError err = EDS_ERR_OK; EdsUInt32 cameraCount = 0 ; err = EdsInitializeSDK(); if(err != EDS_ERR_OK){ printf("Couldn't open sdk!\n"); return false; }else{ printf("Opening the sdk\n"); sdkRef++; } ofSleepMillis(3000); // Initialize // Get the camera list err = EdsGetCameraList(&theCameraList); // Get the number of cameras. if( err == EDS_ERR_OK ){ err = EdsGetChildCount( theCameraList, &cameraCount ); if ( cameraCount == 0 ){ err = EDS_ERR_DEVICE_NOT_FOUND; printf("No devices found!\n"); return false; } } // Get the camera if ( err == EDS_ERR_OK ){ if (cameraID >= cameraCount){ printf("No camera of id %i exists - number of cameras is %i\n", cameraID, cameraCount); return false; } printf("We are opening camera %i!\n", cameraID); err = EdsGetChildAtIndex( theCameraList , cameraID , &theCamera ); //Release camera list if(theCameraList != NULL){ EdsRelease(theCameraList); } if(err == EDS_ERR_OK){ printf("We are connected!\n"); state = CAMERA_READY; //return true; }else{ printf("We are not connected!\n"); state = CAMERA_UNKNOWN; return false; } registerCallback(); return true; } }
boolean connectToFirstCamera(){ EdsError err = EDS_ERR_OK; // Initialize SDK err = EdsInitializeSDK(); if ( err == EDS_ERR_OK ) isSDKLoaded = true; /* // Get first camera if(err == EDS_ERR_OK) { err = getFirstCamera(); }*/ EdsCameraListRef cameraList = NULL; EdsUInt32 count = 0; // Get camera list err = EdsGetCameraList(&cameraList); // Get number of cameras if(err == EDS_ERR_OK) { err = EdsGetChildCount(cameraList, &count); if(count == 0) { err = EDS_ERR_DEVICE_NOT_FOUND; } } // Get first camera retrieved if(err == EDS_ERR_OK) { err = EdsGetChildAtIndex(cameraList , 0 , &camera); } // Release camera list if(cameraList != NULL) { EdsRelease(cameraList); cameraList = NULL; } //Open Session if(err == EDS_ERR_OK) { err = EdsOpenSession(camera); } //Set save to host if (err == EDS_ERR_OK ) { EdsUInt32 wkSaveTo = kEdsSaveTo_Host ; do { err = EdsSetPropertyData ( camera, kEdsPropID_SaveTo, 0, 4, (void*)&wkSaveTo ) ; if (err != EDS_ERR_OK) { std::cout << "warning: camera busy, waiting..." << std::endl; std::flush(std::cout); Sleep(100); } } while (err != EDS_ERR_OK); } // Set host capacity EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1}; err = EdsSetCapacity ( camera, capacity ); return err == EDS_ERR_OK; }