[关闭]
@gnat-xj 2015-11-17T02:31:52.000000Z 字数 4118 阅读 3593

gPhoto2(已经备份)

gPhoto2


0. Bash 指南

Linux 下命令行环境为一种 shell,通常默认为 Bash(borne-again shell)。

Tab 补全

命令不需要全部手敲,按 Tab 键命令可自动补全。如:ec<TAB>(这里的 <TAB> 指的是键盘上的 Tab 键),Bash 会自动补全为 echo,接着敲空格,再 hello Bash,即整个语句是 echo hello Bash,输出为 hello Bash

命令 + 参数

echo 是命令,hello Bash 是参数。结果就是打印 hello Bash 到标准输出流(即命令行)。

man 文档

几乎所有命令都有详细的使用文档,所以不必背太多指令。不知道 gphoto2 怎么用,就 man gphoto2,或者试试 gphoto2 --help,或者直接使用 gphoto2,使用方法会打印在屏幕上:
gphoto2.png

可以把命令写成脚本下次直接使用

拍一张照片用 gphoto2 --capture-image 即可,写到一个文件里比如 run.sh

  1. #/bin/bash
  2. # 这是单行注释,下面是命令
  3. gphoto2 \
  4. --capture-image
  5. : '
  6. 这是多行注释,上面冒号前的两行是命令。反斜杠用来续行,上面的命令等价于
  7. gphoto2 --capture-image
  8. 两种表达一模一样。
  9. 多行注释结束。
  10. '

保存好 run.sh,添加执行权限(不然文本就是文本,不能运行):chmod +x ./run.sh,最后运行:./run.sh,即可拍一张照片。

1. 安装 gPhoto2

参考这篇文章:

  1. # deps
  2. sudo apt-get install \
  3. subversion dh-autoreconf \
  4. libglib2.0-dev \
  5. libusb-dev libusb-1.0-0-dev \
  6. libexif-dev libpopt-dev libfuse-dev \
  7. mono-devel monodoc-base libmono-2.0.1 mono-gmcs \
  8. python-pyrex
  9. # source
  10. wget http://sourceforge.net/projects/gphoto/files/libgphoto/2.5.2/libgphoto2-2.5.2.tar.gz
  11. wget http://sourceforge.net/projects/gphoto/files/gphoto/2.5.2/gphoto2-2.5.2.tar.gz
  12. # unzip, ./configure, make, make install

2. 几个脚本

拍照:(保留一些注释掉的命令)

  1. #/bin/bash
  2. gphoto2 \
  3. --capture-image \
  4. --capture-image \
  5. --capture-image \
  6. : '
  7. 更改一些设置,改一次就好,用了就注释掉
  8. gphoto2 \
  9. --set-config /main/capturesettings/nikonflashmode=3 \
  10. --set-config /main/capturesettings/shootingspeed=3 \
  11. --set-config /main/capturesettings/flashmode=1 \
  12. --set-config /main/capturesettings/shutterspeed=15 \
  13. --set-config /main/capturesettings/shutterspeed2=17 \
  14. --set-config /main/capturesettings/exposuredelaymode=0 \
  15. --set-config /main/capturesettings/burstnumber=1 \
  16. --set-config /main/other/500c=1 \
  17. --set-config /main/other/500d=15 \
  18. --set-config /main/other/500f=0 \
  19. --set-config /main/other/5018=0 \
  20. --set-config /main/other/d068=3 \
  21. --set-config /main/other/d06a=3 \
  22. --set-config /main/other/d1b1=36 \
  23. '
  24. : '
  25. # 这是原来的设置,恢复的时候用
  26. --set-config /main/capturesettings/nikonflashmode=0 \
  27. --set-config /main/capturesettings/shootingspeed=3 \
  28. --set-config /main/capturesettings/flashmode=1 \
  29. --set-config /main/capturesettings/shutterspeed=15 \
  30. --set-config /main/capturesettings/shutterspeed2=17 \
  31. --set-config /main/capturesettings/exposuredelaymode=0 \
  32. --set-config /main/capturesettings/burstnumber=1 \
  33. --set-config /main/other/500c=1 \
  34. --set-config /main/other/500d=15 \
  35. --set-config /main/other/500f=0 \
  36. --set-config /main/other/5018=0 \
  37. --set-config /main/other/d068=3 \
  38. --set-config /main/other/d06a=3 \
  39. --set-config /main/other/d1b1=36 \
  40. '

注意 --capture-preview--capture-image 的区别,可换着试试看。

获取 Thumbnail:

  1. gphoto2 --get-all-thumbnails

thumb_DSC_2221.jpg thumb_DSC_2222.jpg thumb_DSC_2223.jpg

3. 自动分类存到文件夹

  1. #/bin/bash
  2. # BASENAME=$(date +%s_%F_%H:%M:%S_%N)
  3. BASEDIR="/tmp/"
  4. EXTENTION="jpg"
  5. repeat() { while true; do $@; done;};
  6. capture() {
  7. FOLDER="${BASEDIR}./$(date +%F/%H/%M)" && \
  8. IMG="$(date +%s_%F_%H:%M:%S_%N).${EXTENTION}"
  9. mkdir -p $FOLDER
  10. echo @___folder: [$FOLDER]
  11. echo @____image: [$IMG]
  12. # 照相命名并分类保存
  13. gphoto2 --capture-image --filename $IMG && mv $IMG $FOLDER
  14. # echo 'hello(`date +%s`)' > $IMG && mv $IMG $FOLDER
  15. # read -t 1 || return
  16. # echo sleep 3 seconds && sleep 3 && echo sleep done
  17. };
  18. repeat capture # 持续拍照

4. 获取相机的参数

gphoto2 --summary

部分 summary.txt

  1. Camera summary:
  2. Manufacturer: Nikon Corporation
  3. Model: D7100
  4. Version: V1.01
  5. Serial Number: 61778820000000000000000000000000
  6. Vendor Extension ID: 0xa (1.0)
  7. Vendor Extension Description: microsoft.com: 1.0
  8. Capture Formats: JPEG Undefined Type
  9. Display Formats: Undefined Type, Association/Directory, Script, DPOF, Apple Quicktime, JPEG
  10. Device Capabilities:
  11. File Download, File Deletion, File Upload
  12. Generic Image Capture, No Open Capture, Nikon Capture 1, Nikon Capture 2, Nikon Capture 3

list-all-config( <= 点击查看全部内容)

  1. /main/actions/autofocusdrive
  2. Label: Drive Nikon DSLR Autofocus
  3. Type: TOGGLE
  4. Current: 0
  5. /main/actions/manualfocusdrive
  6. Label: Drive Nikon DSLR Manual focus
  7. Type: RANGE
  8. Current: 0
  9. Bottom: -32767
  10. Top: 32767
  11. Step: 1
  12. /main/actions/changeafarea
  13. Label: Set Nikon Autofocus area
  14. Type: TEXT
  15. Current: 0x0
  16. /main/actions/controlmode
  17. Label: Set Nikon Control Mode
  18. Type: TEXT
  19. Current: 0
  20. /main/settings/capturetarget
  21. Label: Capture Target
  22. Type: RADIO
  23. Current: Internal RAM
  24. Choice: 0 Internal RAM
  25. Choice: 1 Memory card

利用这些可以设置相机,比如上面的 /main/settings/capturetarget 的类型是 RADIO,二选一。

那么,设置照片保存在 RAM 上就可以:gphoto2 --set-config /main/settings/capturetarget=0

其他参数也是这样设置。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注