c++ - Canon SDK. Take picture from camera -
i have canon eos d600 camera. need take picture using c++. documentation didn't me. have example code, takes photo? doesn't help:
#include <windows.h> #include <iostream> #include <conio.h> #include <stdio.h> #include <edsdk.h> #include <edsdktypes.h> #include <edsdkerrors.h> using namespace std; edserror getfirstcamera(edscameraref *camera); int main(){ edserror err=eds_err_ok; edscameraref camera=null; bool issdkloaded=false; err=edsinitializesdk(); if(err==eds_err_ok) issdkloaded=true; if(err==eds_err_ok) err=getfirstcamera(&camera); edsopensession(camera); edsint32 savetarget = kedssaveto_host; 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"; edscreatefilestream( ch_dest ,kedsfilecreatedisposition_createalways,kedsaccess_readwrite,0); edssendcommand(camera, kedscameracommand_takepicture, 0); edsclosesession(camera); edsterminatesdk(); return 0; } edserror getfirstcamera(edscameraref *camera) { edserror err=eds_err_ok; edscameralistref cameralist=null; edsuint32 count=0; // camera list err = edsgetcameralist(&cameralist); // number of cameras if(err == eds_err_ok) { err = edsgetchildcount(cameralist, &count); if(count == 0) { err = eds_err_device_not_found; } } // 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; } #include <windows.h> #include <iostream> #include <conio.h> #include <stdio.h> #include <edsdk.h> #include <edsdktypes.h> #include <edsdkerrors.h> using namespace std; edserror getfirstcamera(edscameraref *camera); int main(){ edserror err=eds_err_ok; edscameraref camera=null; bool issdkloaded=false; err=edsinitializesdk(); if(err==eds_err_ok) issdkloaded=true; if(err==eds_err_ok) err=getfirstcamera(&camera); edsopensession(camera); edsint32 savetarget = kedssaveto_host; 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"; edscreatefilestream( ch_dest ,kedsfilecreatedisposition_createalways,kedsaccess_readwrite,0); edssendcommand(camera, kedscameracommand_takepicture, 0); edsclosesession(camera); edsterminatesdk(); return 0; } edserror getfirstcamera(edscameraref *camera) { edserror err=eds_err_ok; edscameralistref cameralist=null; edsuint32 count=0; // camera list err = edsgetcameralist(&cameralist); // number of cameras if(err == eds_err_ok) { err = edsgetchildcount(cameralist, &count); if(count == 0) { err = eds_err_device_not_found; } } // 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; }
having errors: [linker error] undefined reference `imp_edsinitializesdk@0'
help please
hello code works.
#include <iostream> #include "edsdk.h" #include "edsdkerrors.h" #include "edsdktypes.h" #include <thread> #include <chrono> char * directory = "here directory"; void download_img(edsbaseref & object, edsvoid * & context) { edsstreamref stream = null; edsdirectoryiteminfo diriteminfo; edsgetdirectoryiteminfo(object, &diriteminfo); strcat(directory, file_name); edscreatefilestream(directory, kedsfilecreatedisposition_createalways, kedsaccess_readwrite, &stream); edsdownload(object, diriteminfo.size, stream); edsdownloadcomplete(object); edsrelease(stream); stream = null; if (object) edsrelease(object); } edserror edscallback handleobjectevent(edsobjectevent event, edsbaseref object, edsvoid * context) { download_img(object, context); return eds_err_ok; } void init_camera(edscameraref & camera) { edserror err = eds_err_ok; edscameralistref cameralist = null; edsuint32 count = 0; camera = null; err = edsinitializesdk(); err = edsgetcameralist(&cameralist); err = edsgetchildcount(cameralist, &count); if (count > 0) { err = edsgetchildatindex(cameralist, 0, &camera); edsrelease(cameralist); } edssetobjecteventhandler(camera, kedsobjectevent_diritemcreated, handleobjectevent, null); edssendstatuscommand(camera, kedscamerastatuscommand_uiunlock, 0); } void start_liveview(edscameraref camera) { edsopensession(camera); edsuint32 device = kedspropid_evf_outputdevice; edsgetpropertydata(camera, kedspropid_evf_outputdevice, 0, sizeof(device), &device); device |= kedsevfoutputdevice_pc; edssetpropertydata(camera, kedspropid_evf_outputdevice, 0, sizeof(device), &device); } void stop_liveview(edscameraref camera) { edsuint32 device; edsgetpropertydata(camera, kedspropid_evf_outputdevice, 0, sizeof(device), &device); device &= ~kedsevfoutputdevice_pc; edssetpropertydata(camera, kedspropid_evf_outputdevice, 0, sizeof(device), &device); edsclosesession(camera); } void take_video(edscameraref camera, int length) { edsopensession(camera); edsuint32 record_start = 4; // begin movie shooting edssetpropertydata(camera, kedspropid_record, 0, sizeof(record_start), &record_start); this_thread::sleep_for(chrono::milliseconds(length)); edsuint32 record_stop = 0; // end movie shooting edssetpropertydata(camera, kedspropid_record, 0, sizeof(record_stop), &record_stop); edsclosesession(camera); } void update_data(edscameraref camera) { edsopensession(camera); // here event happens edsclosesession(camera); } void take_photo(edscameraref camera, int count, int interv_millsec) { (int = 0; < count; ++i) { edsopensession(camera); cout << "shoot" << endl; edssendcommand(camera, kedscameracommand_takepicture, 0); this_thread::sleep_for(chrono::milliseconds(interv_millsec)); edsclosesession(camera); } update_data(camera); } void dispose(edscameraref camera) { edsclosesession(camera); edsterminatesdk(); } int main (){ edscameraref camera; init_camera(camera); // here may call functions above // take video // firstly have start liveview // secondly call "take video" // thirdly stop liveview return 0; }
Comments
Post a Comment