SLR controlling via computer

Nikolaus Gradwohl2008-10-12T20:40:00+00:00

Today i managed to shoot photos and download them in one step using a little c++ programm. the camera must be set to the MTP/PTP-Mode for this to work. The programm below uses the libgphoto2-API to control the camera and send it a capture command followed by a download command. the library is realy nice to code with, but very badly documented.

test.cpp:

#include <iostream>

extern "C" {
    #include <gphoto2/gphoto2-camera.h>
    #include <gphoto2/gphoto2-setting.h>
}

int main( int argc, char** argv ) {
    CameraFilePath path;
    Camera *camera;
    CameraAbilitiesList *al;
    CameraAbilities abilities;
    GPContext *context;

    GPPortInfoList *infoList;
    GPPortInfo info;

    std::cout << "Hallo" << std::endl;

    gp_camera_new (&camera);

    gp_abilities_list_new (&al);
    gp_abilities_list_load (al, NULL);

    gp_port_info_list_new(&infoList);
    gp_port_info_list_load(infoList);

    int m = gp_abilities_list_lookup_model (al, "Nikon DSC D40x (PTP mode)");
    int p = gp_port_info_list_lookup_path (infoList, "usb:" );

    gp_abilities_list_get_abilities (al, m, &abilities);
    gp_abilities_list_free (al);
    gp_camera_set_abilities (camera, abilities);

    gp_port_info_list_get_info(infoList, p, &info);
    gp_camera_set_port_info(camera, info);
    gp_port_info_list_free( infoList );

    context = gp_context_new ();
    gp_camera_init (camera, context);

    int res = gp_camera_capture (camera, GP_CAPTURE_IMAGE , &path, context);

    if (res >= 0) {
        std::cout  << res << " " << path.folder << " " << path.name  << std::endl;

        CameraFile *cfile;
        gp_file_new(&cfile);
        gp_camera_file_get(camera, path.folder, path.name, GP_FILE_TYPE_NORMAL, cfile, context);
        gp_file_save( cfile, "test.jpg" );
        gp_file_unref( cfile );
    }

    gp_context_unref (context);
    res = gp_camera_unref (camera);
    return 0;
}

Makefile:

CPP      = g++

CPPFLAGS  = -Wall `gphoto2-config --cflags`
LDFLAGS =  `gphoto2-config --libs`

gphoto-test: test.o
    $(CPP)  -o gphoto-test *.o $(LDFLAGS) $(CPPFLAGS)

%.o: %.cpp
    $(CPP)  -c $<

clean:
    rm *.o gphoto-test
Tweet This! submit to reddit Digg! Tags: | no comments | no trackbacks

See also:

Playing with my LOTR lego and my new camera
feeling watched in openframeworks
osc app using openframeworks
nds line-demo
rotating box in openframeworks

Trackbacks

Comments

Leave a response

Leave a comment