DSLR camera control - adding Objective C code

Hello - I probably have no business doing this as a noob, but I needed to be able to control a DSLR camera and analyze the pictures from it and thought I’d try to do it in OF. I found a good library from Apple of Objective C code from their Image Capture SDK that works well for scanning camera capabilities, automatically triggering the shutter, and downloading photos. Pretty useful.

Anyway, I tried to mash these files into OF and, after some fiddling am down to only 11 errors! They all seem to be in the genre of Objective C things that won’t compile, such as NSString. A complete list of errors is here.

I began with just the OF blob tracking code and an trying to build this in. I’ve uploaded the code if anyone would like to take a look -it-is-here. Followed a couple of the tutorials online (you’ll notice I changed .m to .mm per the suggestion of these) but I’m obviously missing something.

I’d love to be able to use these libraries if anyone has any suggestions. Thanks!

Ian

Hi - almost there :smiley:

Add

  
-framework Foundation -framework AppKit  

To your Project Settings->Build->Linking->Other Linker Flags

Mine now reads

  
../../../libs/freetype/lib/freetype.a ../../../libs/freeimage/lib/freeimage.a ../../../libs/fmodex/lib/libfmodex.dylib ../../../libs/GLee/lib/GLee.a ../../../libs/rtAudio/lib/rtAudio.a -framework Carbon -framework GLUT -framework Foundation -framework CoreFoundation -framework OpenGL -framework AppKit -framework QuickTime -framework ApplicationServices -framework AudioToolbox -framework CoreAudio -framework CoreServices -framework AGL ../../../addons/ofxOpenCv/libs/opencv/lib/osx/libOpenCV.a ../../../addons/ofxOsc/libs/oscpack/lib/osx/libOsc.a  

And it compiles fine.

In the future if you get errors like this at the linking stage it will usually be that the app is missing a framework - so if you google the Error with the word “framework” then you should be able to easily find which framework you are missing.

ie google “NSMutableArray framework”

Hope that helps!

Camera triggering sounds very exciting would you mind posting another app when you have a simple demo up and running?

Cheers!
Theo

Hmm on seconds thoughts I am not sure how you will include the objective-c code within the OF code.

Trying to include or import “CameraMessages.h” makes 4000 errors.

:?

http://developer.apple.com/documentatio-…-3-CH10-SW1

Looks like it is easy to include C++ inside an objective-c file but not sure about the other way round.

Theo

Thank you for looking into it. There are a few other possibilities for camera triggering that I’ve been looking into (gphoto) - this seemed to work the best though - sad it’s not compiling. I’ll keep you updated if I come up with anything.

fyi – I have had good luck w/ canon powershot sdk (with a G7/G9) recently for a project. only works on a pc (not on vista though) and it not so hard to use. We have code around if you need to give it a try. I guess they are discontinuing the sdk, but they also have one for the DSLR line (eos, etc). Great quality and can save to disk / load into OF quite easily…

hey,zach,is it possible to share the example,i want to try it with my new canon powershot sx100. thank you!

You should check out PS Remote
http://www.breezesys.com/PSRemote/index.htm

I’ve successfully used it with Processing and am going to make a wrapper for it in ofw as using it on something now.

“PSRemote also includes a DLL and a sample program (complete with C++ source code) which allows other applications to release the camera’s shutter and adjust the shutter speed and aperture.”

Hmm on seconds thoughts I am not sure how you will include the objective-c code within the OF code.

You definitely want to keep the Objective-C code as contained as possible. The best way I’ve found to create generic interfaces to platform-specific functionality (including different languages like ObjC) is with the PIMPL idiom. What’s really nice about it is that it allows you to separate the logic of how things are controlled from the actual implementation.

The basic idea is to include an opaque pointer (usually with something like

  
std::auto_ptr<Implementation> mImpl;  

) where Implementation is the opaque platform-specific class. The class Implementation will be forward-declared and defined in a .cpp or .mm so it remains hidden from anything that might include the header file. For an example, see the following source files that demonstrate the use of PIMPL for a platform agnostic Window class:

Generic header file:
https://svn.mat.ucsb.edu/svn/luaAV/bran-…-AVWindow.h

Generic source file (the logic):
https://svn.mat.ucsb.edu/svn/luaAV/bran-…-Window.cpp

Implementation source file:
https://svn.mat.ucsb.edu/svn/luaAV/bran-…-owCocoa.mm

Hmm on seconds thoughts I am not sure how you will include the objective-c code within the OF code.

You definitely want to keep the Objective-C code as contained as possible. The best way I’ve found to create generic interfaces to platform-specific functionality (including different languages like ObjC) is with the PIMPL idiom. What’s really nice about it is that it allows you to separate the logic of how things are controlled from the actual implementation.

The basic idea is to include an opaque pointer (usually with something like

  
std::auto_ptr<Implementation> mImpl;  

) where Implementation is the opaque platform-specific class. The class Implementation will be forward-declared and defined in a .cpp or .mm so it remains hidden from anything that might include the header file. For an example, see the following source files that demonstrate the use of PIMPL for a platform agnostic Window class:

Generic header file:
https://svn.mat.ucsb.edu/svn/luaAV/bran-…-AVWindow.h

Generic source file (the logic):
https://svn.mat.ucsb.edu/svn/luaAV/bran-…-Window.cpp

Implementation source file:
https://svn.mat.ucsb.edu/svn/luaAV/bran-…-owCocoa.mm

[quote author=“chrisoshea”]You should check out PS Remote
http://www.breezesys.com/PSRemote/index.htm

I’ve successfully used it with Processing and am going to make a wrapper for it in ofw as using it on something now.

“PSRemote also includes a DLL and a sample program (complete with C++ source code) which allows other applications to release the camera’s shutter and adjust the shutter speed and aperture.”[/quote]

thanks for this,looks pretty good

i’m having a go at this now
a ‘ofxDSLR’. i’m using gphoto2 on mac
(cheating to get it to build by using macports :)!)

got it taking snaps, just need to make it load them in a useful state
16bit images should also be possible (but then have to fiddle with cr2’s)

bah. back to the old 32bit/64bit problem

anybody know of a quick way to use ‘make’ on a library to compile it 32bit?

if i set my openframeworks project to be 64bit then i get a bunch of quicktime complaints
might have to disable qt