Coder Social home page Coder Social logo

gphoto2go's Introduction

gPhoto2-Go

A more Go idiomatic interface to the gPhoto2 library.

Warning

I'm not a great Golang programmer, so this could be a complete disaster. But, if you want to use the gPhoto2 library and you'd prefer to avoid sticking cgo references all over your main Go program, this library might help.

I'm also not a great C programmer, having grown up with garbage collectors and other niceties. Therefore, this library will be riddled with memory leaks. I would appreciate any help in making it more memory efficient.

Installation

go get github.com/micahwedemeyer/gphoto2go

Requirements

You will also need libgphoto2 installed. If you are on Mac OS X, I recommend installing it with homebrew.

brew install libgphoto2

This should now compile by itself thanks to this // #cgo pkg-config: libgphoto2

Usage

The main goal with this library is to present a Go-friendly interface to the C methods of gPhoto2

Camera Initializing

camera := new(gphoto2go.Camera)
err := camera.Init()

This will create a new Camera struct and intitialize it, which prompts gphoto2 to auto-detect any connected USB cameras.

Taking a Photo

camera.TriggerCapture()

This will trigger the camera.

Downloading the Photos from the Camera

folders := camera.RListFolders("/")
for _, folder := range folders {
    files, _ := camera.ListFiles(folder)
    for _, fileName := range files {
        cameraFileReader := camera.FileReader(folder, fileName)
        fileWriter := os.Create("/tmp/" + fileName)
        io.Copy(fileWriter, cameraFileReader)

        // Important, since there is memory used in the transfer that needs to be freed up
        cameraFileReader.Close()
    }
}

Interpreting errors

Most of the functions will return an error code. If it is less than zero, that means an error has occurred. The library can translate the error integer into a human readable string.

err := camera.TriggerCapture()
if err < 0 {
    fmt.Printf(gphoto2go.CameraResultToString(err))
}

gphoto2go's People

Contributors

micahwedemeyer avatar charles-d-burton avatar mrmod avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.