Controlling a camera in Linux – continued | The Parallellogram

Link

exposurecompensation

Source: https://parallellogram.wordpress.com/2014/09/30/controlling-a-camera-in-linux/

Controlling a camera in Linux – continued | The Parallellogram

 

Controlling a camera in Linux

Here is a quick guide on controlling a camera from Linux. I first messed around with this in early 2011. Without (yet) a means to move/position the camera, I have found little use for it – but perhaps you may find it useful.

Obviously there are various applications, such as bracketing (possibly for HDR), and time lapse (intervalometer), which do not require movement of the camera (indeed it should he held steady), but many cameras have support for this – since I have upgraded my DSLR, these became less relevant for me.

Once you add the ability to swivel the camera, this adds additional applications such as programing/choreographing video, or taking long exposures of the night sky (automatically tracking with the rotation of the earth). These are obviously best done with a portable setup, ideally with the ability to control motors / path via a readily available UI, such as an Android phone. Using the gyro/accelerometer available in any modern smartphone, inclination of the camera can be managed this way, if you (and your camera!) are this way inclined 🙂

You could do all this with an 8-bit micro (see previous post), and a BT UART link – but if you want to load/process the images, this is where the processing power of the Parallella comes in.

I use gphoto2, a nifty command-line app built on libgphoto2. The list of supported cameras can be found here.

Note that I have no bothered with configuring udev rules to set permissions for non-root users. I might cover this in a later post.

Install gphoto2:

sudo apt-get install gphoto2

Connect the camera (using an OTG cable). If you type dmesg, you should see something like:

usb 1-1: new high-speed USB device number 3 using zynq-ehci


linaro-nano:~> sudo gphoto2 --auto-detect
Model Port
----------------------------------------------------------
Nikon DSC D60 (PTP mode) usb:001,003

As you can see, it has detected my Nikon D60 – my old project DSLR which is the victim of my various experiments. If I want further information about the camera, the following command has useful output.


linaro-nano:~> sudo gphoto2 --summary

Now, to show we are reading the current information from the camera:

linaro-nano:~> sudo gphoto2 --get-config=/main/capturesettings/focallength
Label: Focal Length
Type: RANGE
Current: 55
Bottom: 55
Top: 200
Step: 0.01

And now I twirl the zoom knob on the 55-200mm VR lens:

linaro-nano:~> sudo gphoto2 --get-config=/main/capturesettings/focallength
Label: Focal Length
Type: RANGE
Current: 105
Bottom: 55
Top: 200
Step: 0.01

And so we see the focal length has moved from 55mm to 105mm – thus we can read the current configuration of the camera.

In previous hacking, I used an 8-bit AVR with a usb host chip to dump the current aperture, focal length, and exposure settings to an LCD screen. Note that you can also control some of the settings.

You can obtain a list of the supported settings by running

sudo gphoto2 --list-config

Say I then see the ISO setting, and want to see whether I can control this.

linaro-nano:~> sudo gphoto2 --list-config | grep iso
/main/imgsettings/iso
/main/imgsettings/isoauto
/main/imgsettings/autoiso
/main/capturesettings/isoautohilimit
linaro-nano:~> sudo gphoto2 --get-config=/main/imgsettings/iso
Label: ISO Speed
Type: RADIO
Current: 1600
Choice: 0 100
Choice: 1 200
Choice: 2 400
Choice: 3 800
Choice: 4 1600
Choice: 5 3200

So there are 6 settings I can use (the camera was already in autoiso mode – if it was not, likely this command would fail until you set the correct mode). I now wish to set it to 200.


linaro-nano:~> sudo gphoto2 --set-config=/main/imgsettings/iso=200

linaro-nano:~> sudo gphoto2 –get-config=/main/imgsettings/iso
Label: ISO Speed
Type: RADIO
Current: 200
Choice: 0 100
Choice: 1 200
Choice: 2 400
Choice: 3 800
Choice: 4 1600
Choice: 5 3200
linaro-nano:~>

And I can confirm via the camera display that it has indeed set the ISO to 200.

As for triggering a capture, I will demonstrate how to take a bracket of 3 images:

linaro-nano:~> sudo gphoto2 --set-config /main/capturesettings/exposurecompensation=12 --trigger-capture
linaro-nano:~> sudo gphoto2 --set-config /main/capturesettings/exposurecompensation=15 --trigger-capture
linaro-nano:~> sudo gphoto2 --set-config /main/capturesettings/exposurecompensation=18 --trigger-capture

This has taken a series of 3 exposures, storing them on my camera.

I’m now switching to ArchLinux since the gphoto2 2.5.3 which comes with Ewwbuntu does not seem to perform the –capture-image and –capture-image-and-download functions correctly.

With ubuntu, you can use the following workaround:

linaro-nano:~> sudo gphoto2 --list-files

and download all the photos using

linaro-nano:~> sudo gphoto2 --get-all-files
Downloading 'curve.ntc' from folder '/special'...
Saving file as curve.ntc
Downloading 'DSC_2356.NEF' from folder '/store_00010001/DCIM/100NCD60'...
Saving file as DSC_2356.NEF
....

But the way I generally do this, as shown using gphoto2 2.5.4 running on ArchLinux is:

[root@ParallellArch ~]# gphoto2 --trigger-capture
[root@ParallellArch ~]# gphoto2 --capture-image
New file is in location /capt0000.nef on the camera
[root@ParallellArch ~]# gphoto2 --capture-image-and-download
New file is in location /capt0000.nef on the camera
Saving file as capt0000.nef
Deleting file /capt0000.nef on the camera
Deleting 'capt0000.nef' from folder '/'...
[root@ParallellArch ~]# ls -l capt0000.nef; strings capt0000.nef | head -2
-rw-r--r-- 1 root root 7624570 Oct 1 20:48 capt0000.nef
NIKON CORPORATION
NIKON D60

Please see my followup post on the differences between these three commands (all of which cause the camera to take a photo).

Similarly, if I had hooked up my Nikon D7000, which has LiveView, I expect I would be able to capture a movie using <code>–capture-movie</code>. Since I have only had the D7000 for 2 years, I haven’t yet explored the added functionality this may offer in terms of controlability, but I will do so in the coming months.

My old D60 does not appear to support setting the focus at all, while apparently even on newer Nikon and Cannon cameras this is quite limited.

This is a bit disappointing, however I expect for most applications of unattended photography, you will be using autofocus, or an unchanging manual focus (say infinity, for stellar photography).

Ultimately I intend to drive the zoom ring using a motor, so may also consider doing this for the focus ring. But this is fairly far into the future, and only really needed if I implement real-time target acquisition and can manually focus on the strength of this better than the camera can (a bit of a pipe dream).

Soon, I will be exploring the Python library for gphoto2, and will provide a separate post using this.

 

Controlling a camera in Linux – continued

Last post, I looked at what we could do on my old Nikon D60 DSLR connected to the Parallella using both Ubuntu and ArchLinux. This time, I will see what extended options there are on a newer DSLR, in this case the Nikon D7000.

As there are some issues with the 2.5.3 version shipping with Ubuntu, so I will use ArchLinux for this post also.

I found with the D7000 that unless I turned the camera on before connecting the USB, it failed to enumerate. This was true with both my desktop and the Parallella (both of which run ArchLinux).

Unlike the D60, as I hinted at last time, the D7000 supports driving the focus. Although this is restricted to LiveView mode.

[root@ParallellArch ~]# gphoto2 --get-config /main/actions/manualfocusdrive
Label: Drive Nikon DSLR Manual focus
Type: RANGE
Current: 0
Bottom: -32767
Top: 32767
Step: 1

The only way I have been able to make use of the focus is by entering the interactive shell – when you use gphoto2 in this manner, the mirror remains locked up after a call to capture-preview (if you call it non-interactively, it will drop immediately after capturing a preview image).

$ gphoto2 --shell
gphoto2: {/home/yani} /> capture-preview
Saving file as capture_preview.jpg
gphoto2: {/home/yani} /> set-config /main/actions/manualfocusdrive=-500
gphoto2: {/home/yani} /> set-config /main/actions/manualfocusdrive=500
gphoto2: {/home/yani} /> set-config /main/actions/manualfocusdrive=-500
gphoto2: {/home/yani} /> set-config /main/actions/manualfocusdrive=500
gphoto2: {/home/yani} /> exit

and so I see the focus ring driven back and forth. The call to capture-preview causes the mirror to be left up. As soon as you exit the shell, you will hear the mirror being dropped.

I can also record LiveView movies using

[root@ParallellArch ~]# gphoto2 --capture-movie
Capturing preview frames as movie to 'movie.mjpg'. Press Ctrl-C to abort.
^C
Cancelling...
Ctrl-C pressed ... Exiting.
Movie capture finished (162 frames)
[root@ParallellArch ~]# ls -l movie.mjpg; file movie.mjpg
-rw-r----- 1 root root 5285244 Oct 1 09:30 movie.mjpg
movie.mjpg: JPEG image data, baseline, precision 0, 4360x426

The resultant motion JPEG file can then be loaded directly into smplayer. You can of course convert this to something like mpeg or avi (for example using ffmpeg or mencoder).

But after each operation, the mirror is lowered. According to this post (dated 2012), locking up the mirror on a Canon is no small feat. However I am sure I must be missing something.

There are other cool things you can do, which may be useful in my project down the track, so I will give them a mention here. You can select the currently lit AF point. The D7000 has a 39-point AF. Mine was set to 2, so I reprogrammed it to 22. I did this while peering into the viewfinder and saw it immediately move. This represents a nifty ability to programmatically configure where the camera will focus, by determining which quadrant the subject will be in (by whatever means), and telling the camera to autofocus on that part of the AF matrix.

[root@ParallellArch ~]# gphoto2 --get-config d108
Label: Active AF Sensor
Type: MENU
Current: 2
Choice: 0 1
.....
Choice: 38 39
[root@ParallellArch ~]# gphoto2 --set-config d108=22
[root@ParallellArch ~]# gphoto2 --get-config d108
Label: Active AF Sensor
Type: MENU
Current: 22

Since my D7000 shoots in JPG+RAW, I get two images each time I take an exposure:

[root@ParallellArch ~]# gphoto2 --capture-image-and-download
New file is in location /capt0000.jpg on the camera
Saving file as capt0000.jpg
Deleting file /capt0000.jpg on the camera
Deleting 'capt0000.jpg' from folder '/'...
New file is in location /capt0001.nef on the camera
Saving file as capt0001.nef
Deleting file /capt0001.nef on the camera
Deleting 'capt0001.nef' from folder '/'...

I mentioned in my previous post that I would explain the differences between –trigger-capture, –capture-image, and –capture-image-and-download. The first simply causes the camera to take an exposure, so is the command to use if trying to take a short burst with varying exposure settings (a bracketed shot). While you won’t then see any new photo if you use –list-files (and it won’t be saved to the SD card), a subsequent download will indeed fetch the photo. The second causes an image to be capture, sent over PTP, and ultimately discarded. I think this command is utterly pointless. All it tells you is what the captured file was named (but at the huge inefficiency of sending the whole file!). The final option captures an image, and then downloads ALL files. So if you previously used –trigger-capture, it will send you your file. However if you previously used –capture-image, it will not send you both – it will replace the existing file! Confused? Good – not the most intuitive interface.

Here is an example of me taking a bracketed exposure, and then retrieving the files

[root@ParallellArch ~]# gphoto2 --set-config /main/capturesettings/exposurecompensation=12 --trigger-capture
[root@ParallellArch ~]# gphoto2 --set-config /main/capturesettings/exposurecompensation=15 --trigger-capture
[root@ParallellArch ~]# gphoto2 --set-config /main/capturesettings/exposurecompensation=18 --trigger-capture
[root@ParallellArch ~]# gphoto2 --capture-image-and-download
New file is in location /capt0000.jpg on the camera
Saving file as capt0000.jpg
Deleting file /capt0000.jpg on the camera
Deleting 'capt0000.jpg' from folder '/'...
New file is in location /capt0001.nef on the camera
Saving file as capt0001.nef
Deleting file /capt0001.nef on the camera
Deleting 'capt0001.nef' from folder '/'...
New file is in location /capt0002.jpg on the camera
Saving file as capt0002.jpg
Deleting file /capt0002.jpg on the camera
Deleting 'capt0002.jpg' from folder '/'...
New file is in location /capt0003.nef on the camera
Saving file as capt0003.nef
Deleting file /capt0003.nef on the camera
Deleting 'capt0003.nef' from folder '/'...
New file is in location /capt0004.jpg on the camera
Saving file as capt0004.jpg
Deleting file /capt0004.jpg on the camera
Deleting 'capt0004.jpg' from folder '/'...
New file is in location /capt0005.nef on the camera
Saving file as capt0005.nef
Deleting file /capt0005.nef on the camera
Deleting 'capt0005.nef' from folder '/'...
New file is in location /capt0006.jpg on the camera
Saving file as capt0006.jpg
Deleting file /capt0006.jpg on the camera
Deleting 'capt0006.jpg' from folder '/'...
New file is in location /capt0007.nef on the camera
Saving file as capt0007.nef
Deleting file /capt0007.nef on the camera
Deleting 'capt0007.nef' from folder '/'...

What just happened? Why 8 images? Remember I am shooting RAW+JPG – so each exposure generates two files. Finally, because –capture-image-and-download causes a final image to be taken, the 3 shots results in 8 images. I could have substituted –trigger-capture with –capture-image-and-download for the last shot, and not generated any wasted captures/transfers.

Note that all of the above writed photos to SDRAM only – which can then be retrieved via USB. In order to save to the camera’s internal SD cards (the D7000 has dual slots), I found you need to use

gphoto2 --set-config=capturetarget=1

If you keep track of the number of the last recorded image, take a flurry of shots, it should be possible to query the list of available files and selectively retrieve just the newer ones you wish to store, process, upload to the cloud, or whatever.

Obviously this is the only mode you should use for the likes of my earlier 8-bit AVR driven approach, since I had a device triggering the captures which had nowhere near the capabilities required to retrieve and store the photos. This is no issue with the Parallella – but in the interests of preserving backups of photos, limiting the need to saturate the USB link fetching photos too often, and risking losing un-fetched images, I intend to save to the SD card always, and then only retrieve photos as needed.

Obviously there are a whole lot of other functions I would like to explore, in particular things like focus lock and exposure lock for taking panoramas, or preventing AF from hesitating at the wrong moment when you have a shot all setup, but it wants to seek. I will add further details as I explore these. I am not sure how much will require the camera to be correctly configured via the UI, and how much we can do via USB control. Since the D7000 provides two save slots for the entire camera configuration, which can then be saved to and restored from card, it is not too onerous to use a different card when I go out shooting versus when in the platform – but not all cameras afford this luxury, and I prefer the idea of programming it via PTP.

Ubuntu Manpage: solve-field – Main high-level command-line user interface.

Link

Upper bound of image scale estimate

Source: Ubuntu Manpage: solve-field – Main high-level command-line user interface.

 

DESCRIPTION

       Main high-level command-line user interface for astrometry.net

       You can specify http:// or  ftp://  URLs  instead  of  filenames.   The
       "wget" or "curl" program will be used to retrieve the URL.

       The  astrometry  engine  will  take any image and return the astrometry
       world coordinate system (WCS), ie a standards-based description of  the
       (usually  nonlinear)  transformation  between image coordinates and sky
       coordinates with absolutely no “false positives” (but  maybe  some  “no
       answers”).  It  will  do  its best, even when the input image has no or
       totally incorrect meta data.

OPTIONS

       -h, --help
              Print the help message

       -v, --verbose
              Be more chatty. Repeat for even more verboseness

       -D, --dir directory
              Place all output files in the specified directory

       -o, --out file
              Name the output files with this base name

       -b, --backend-config file
              Use this config file for the "astrometry-engine" program

       --config file
              Use this config file for the "astrometry-engine" program

       --batch
              Run astrometry-engine once, rather than once per input file

       -f, --files-on-stdin
              Read filenames to solve on stdin, one per line

       -p, --no-plots
              Don't create any plots of the results

       --plot-scale scale
              Scale the plots by this factor (eg, 0.25)

       --plot-bg file
              Set the background image to use for plots (JPEG)

       -G, --use-wget
              Use wget instead of curl

       -O, --overwrite
              Overwrite output files if they already exist

       -K, --continue
              Don't overwrite output files if they already exist;  continue  a
              previous run

       -J, --skip-solved
              Skip  input  files  for  which  the 'solved' output file already
              exists; NOTE: this assumes single-field input files

       --fits-image
              assume the input files are FITS images

       -N, --new-fits file
              Output filename of the new FITS file containing the WCS  header;
              "none" to not create this file

       -Z, --kmz file
              Create KMZ file for Google Sky. (requires wcs2kml)

       -i, --scamp file
              Create image object catalog for SCAMP

       -n, --scamp-config file
              Create SCAMP config file snippet

       -U, --index-xyls file
              Output  filename  for  xylist containing the image coordinate of
              stars from the index

       --just-augment
              Just write the augmented xylist  files;  don't  run  astrometry-
              engine.

       --axy file
              Output filename for augment xy list (axy)

       --temp-axy
              Write 'augmented xy list' (axy) file to a temp file

       --timestamp
              Add timestamps to log messages

       -7, --no-delete-temp
              Don't delete temp files (for debugging)

       -L, --scale-low scale
              Lower bound of image scale estimate

       -H, --scale-high scale
              Upper bound of image scale estimate

       -u, --scale-units units
              In what units are the lower and upper bounds? Choices:

              "degwidth", "degw", "dw"
                     width of the image, in degrees (default)

              "arcminwidth", "amw", "aw"
                     width of the image, in arcminutes

              "arcsecperpix", "app"
                     arcseconds per pixel

              "focalmm"
                     35-mm (width-based) equivalent focal length

       -8, --parity pos/neg
              Only  check  for matches with positive/negative parity (default:
              try both)

       -c, --code-tolerance distance
              Matching distance for quads (default: 0.01)

       -E, --pixel-error pixels
              For verification, size of pixel positional error (default: 1)

       -q, --quad-size-min fraction
              Minimum size of quads to try, as a fraction of the smaller image
              dimension, default: 0.1

       -Q, --quad-size-max fraction
              Maximum  size  of  quads  to  try,  as  a  fraction of the image
              hypotenuse, default 1.0

       --odds-to-tune-up odds
              Odds ratio at which to try tuning up a  match  that  isn't  good
              enough to solve (default: 1e6)

       --odds-to-solve odds
              Odds ratio at which to consider a field solved (default: 1e9)

       --odds-to-reject odds
              Odds ratio at which to reject a hypothesis (default: 1e-100)

       --odds-to-stop-looking odds
              Odds  ratio  at  which  to  stop  adding stars when evaluating a
              hypothesis (default: HUGE_VAL)

       --use-sextractor
              Use SExtractor rather than built-in image2xy to find sources

       --sextractor-config file
              Use the given SExtractor config file. Note that CATALOG_NAME and
              CATALOG_TYPE  values will be over-ridden by command-line values.
              This option implies --use-sextractor.

       --sextractor-path file
              Use the given path to the SExtractor executable.  Default:  just
              'sextractor', assumed to be in your PATH. Note that you can give
              command line args here too (but put them in quotes), eg:

              --sextractor-path 'sextractor -DETECT_TYPE CCD'.

              This option implies --use-sextractor.

       -3 RA, --ra RA
              RA of field center for search, format: degrees or hh:mm:ss

       -4 DEC, --dec DEC
              DEC of field center for search, format: degrees or hh:mm:ss

       -5 degrees, --radius degrees
              Only search in indexes within 'radius' of the field center given
              by --ra and --dec

       -d, --depth number or range
              Number  of  field  objects to look at, or range of numbers; 1 is
              the brightest star, so "-d 10" or "-d 1-10" mean look at the top
              ten brightest stars only.

       --objs int
              Cut  the  source list to have this many items (after sorting, if
              applicable).

       -l, --cpulimit seconds
              Give up solving after the specified number  of  seconds  of  CPU
              time

       -r, --resort
              Sort  the  star  brightnesses by background-subtracted flux; the
              default    is    to    sort    using     acompromise     between
              background-subtracted and non-background-subtracted flux

       -6, --extension int
              FITS extension to read image from.

       -2, --no-fits2fits
              Don't sanitize FITS files; assume they're already valid

       --invert
              Invert the image (for black-on-white images)

       -z, --downsample int
              Downsample  the  image  by  factor  int  before  running  source
              extraction

       --no-background-subtraction
              Don't try to estimate a smoothly-varying sky  background  during
              source extraction.

       --sigma float
              Set the noise level in the image

       -9, --no-remove-lines
              Don't remove horizontal and vertical overdensities of sources.

       --uniformize int
              Select   sources   uniformly   using  roughly  this  many  boxes
              (0=disable; default 10)

       --no-verify-uniformize
              Don't uniformize the field stars during verification

       --no-verify-dedup
              Don't deduplicate the field stars during verification

       -0, --no-fix-sdss
              Don't try to fix SDSS idR files.

       -C, --cancel file
              Filename whose creation signals the process to stop

       -S, --solved file
              Output file to mark that the solver succeeded

       -I, --solved-in file
              Input filename for solved file

       -M, --match file
              Output filename for match file

       -R, --rdls file
              Output filename for RDLS file

       --sort-rdls column
              Sort the RDLS file by this column;  default  is  ascending;  use
              "-column" to sort "column" in descending order instead.

       --tag column
              Grab tag-along column from index into RDLS file

       --tag-all
              Grab all tag-along columns from index into RDLS file

       -j, --scamp-ref file
              Output filename for SCAMP reference catalog

       -B, --corr file
              Output filename for correspondences

       -W, --wcs file
              Output filename for WCS file

       -P, --pnm file
              Save the PNM file as file

       -k, --keep-xylist file
              Save the (unaugmented) xylist to file

       -A, --dont-augment
              Quit after writing the unaugmented xylist

       -V, --verify file
              Try to verify an existing WCS file

       --verify-ext extension
              HDU from which to read WCS to verify; set this BEFORE --verify

       -y, --no-verify
              Ignore existing WCS headers in FITS input images

       -g, --guess-scale
              Try to guess the image scale from the FITS headers

       --crpix-center
              Set the WCS reference point to the image center

       --crpix-x pix
              Set the WCS reference point to the given position

       --crpix-y pix
              Set the WCS reference point to the given position

       -T, --no-tweak
              Don't fine-tune WCS by computing a SIP polynomial

       -t, --tweak-order int
              Polynomial order of SIP WCS corrections

       -m, --temp-dir dir
              Where to put temp files, default /tmp

   The following options are valid for xylist inputs only:
       -F, --fields number or range
              The FITS extension(s) to solve, inclusive

       -w, --width pixels
              Specify the field width

       -e, --height pixels
              Specify the field height

       -X, --x-column column-name
              The FITS column containing the X coordinate of the sources

       -Y, --y-column column-name
              The FITS column containing the Y coordinate of the sources

       -s, --sort-column column-name
              The FITS column that should be used to sort the sources

       -a, --sort-ascending
              Sort  in ascending order (smallest first); default is descending
              order

       Note that most output files can be disabled by setting the filename  to
       "none".   (If  you  have  a sick sense of humour and you really want to
       name your output file "none", you can use "./none" instead.)

AUTHOR

       The Astrometry.net team. Principal  investigators  are  David  W.  Hogg
       (NYU) and Dustin Lang (CMU).

SEE ALSO

       http://astrometry.net