@gnat-xj
2015-11-17T02:31:52.000000Z
字数 4118
阅读 3911
gPhoto2
Linux 下命令行环境为一种 shell,通常默认为 Bash(borne-again shell)。
命令不需要全部手敲,按 Tab 键命令可自动补全。如:ec<TAB>(这里的 <TAB> 指的是键盘上的 Tab 键),Bash 会自动补全为 echo,接着敲空格,再 hello Bash,即整个语句是 echo hello Bash,输出为 hello Bash。
echo 是命令,hello Bash 是参数。结果就是打印 hello Bash 到标准输出流(即命令行)。
几乎所有命令都有详细的使用文档,所以不必背太多指令。不知道 gphoto2 怎么用,就 man gphoto2,或者试试 gphoto2 --help,或者直接使用 gphoto2,使用方法会打印在屏幕上:

拍一张照片用 gphoto2 --capture-image 即可,写到一个文件里比如 run.sh:
#/bin/bash# 这是单行注释,下面是命令gphoto2 \--capture-image: '这是多行注释,上面冒号前的两行是命令。反斜杠用来续行,上面的命令等价于gphoto2 --capture-image两种表达一模一样。多行注释结束。'
保存好 run.sh,添加执行权限(不然文本就是文本,不能运行):chmod +x ./run.sh,最后运行:./run.sh,即可拍一张照片。
参考这篇文章:
# depssudo apt-get install \subversion dh-autoreconf \libglib2.0-dev \libusb-dev libusb-1.0-0-dev \libexif-dev libpopt-dev libfuse-dev \mono-devel monodoc-base libmono-2.0.1 mono-gmcs \python-pyrex# sourcewget http://sourceforge.net/projects/gphoto/files/libgphoto/2.5.2/libgphoto2-2.5.2.tar.gzwget http://sourceforge.net/projects/gphoto/files/gphoto/2.5.2/gphoto2-2.5.2.tar.gz# unzip, ./configure, make, make install
#/bin/bashgphoto2 \--capture-image \--capture-image \--capture-image \: '更改一些设置,改一次就好,用了就注释掉gphoto2 \--set-config /main/capturesettings/nikonflashmode=3 \--set-config /main/capturesettings/shootingspeed=3 \--set-config /main/capturesettings/flashmode=1 \--set-config /main/capturesettings/shutterspeed=15 \--set-config /main/capturesettings/shutterspeed2=17 \--set-config /main/capturesettings/exposuredelaymode=0 \--set-config /main/capturesettings/burstnumber=1 \--set-config /main/other/500c=1 \--set-config /main/other/500d=15 \--set-config /main/other/500f=0 \--set-config /main/other/5018=0 \--set-config /main/other/d068=3 \--set-config /main/other/d06a=3 \--set-config /main/other/d1b1=36 \': '# 这是原来的设置,恢复的时候用--set-config /main/capturesettings/nikonflashmode=0 \--set-config /main/capturesettings/shootingspeed=3 \--set-config /main/capturesettings/flashmode=1 \--set-config /main/capturesettings/shutterspeed=15 \--set-config /main/capturesettings/shutterspeed2=17 \--set-config /main/capturesettings/exposuredelaymode=0 \--set-config /main/capturesettings/burstnumber=1 \--set-config /main/other/500c=1 \--set-config /main/other/500d=15 \--set-config /main/other/500f=0 \--set-config /main/other/5018=0 \--set-config /main/other/d068=3 \--set-config /main/other/d06a=3 \--set-config /main/other/d1b1=36 \'
注意 --capture-preview 和 --capture-image 的区别,可换着试试看。
gphoto2 --get-all-thumbnails

#/bin/bash# BASENAME=$(date +%s_%F_%H:%M:%S_%N)BASEDIR="/tmp/"EXTENTION="jpg"repeat() { while true; do $@; done;};capture() {FOLDER="${BASEDIR}./$(date +%F/%H/%M)" && \IMG="$(date +%s_%F_%H:%M:%S_%N).${EXTENTION}"mkdir -p $FOLDERecho @___folder: [$FOLDER]echo @____image: [$IMG]# 照相命名并分类保存gphoto2 --capture-image --filename $IMG && mv $IMG $FOLDER# echo 'hello(`date +%s`)' > $IMG && mv $IMG $FOLDER# read -t 1 || return# echo sleep 3 seconds && sleep 3 && echo sleep done};repeat capture # 持续拍照
gphoto2 --summary部分 summary.txt:
Camera summary:Manufacturer: Nikon CorporationModel: D7100Version: V1.01Serial Number: 61778820000000000000000000000000Vendor Extension ID: 0xa (1.0)Vendor Extension Description: microsoft.com: 1.0Capture Formats: JPEG Undefined TypeDisplay Formats: Undefined Type, Association/Directory, Script, DPOF, Apple Quicktime, JPEGDevice Capabilities:File Download, File Deletion, File UploadGeneric Image Capture, No Open Capture, Nikon Capture 1, Nikon Capture 2, Nikon Capture 3
list-all-config( <= 点击查看全部内容)
/main/actions/autofocusdriveLabel: Drive Nikon DSLR AutofocusType: TOGGLECurrent: 0/main/actions/manualfocusdriveLabel: Drive Nikon DSLR Manual focusType: RANGECurrent: 0Bottom: -32767Top: 32767Step: 1/main/actions/changeafareaLabel: Set Nikon Autofocus areaType: TEXTCurrent: 0x0/main/actions/controlmodeLabel: Set Nikon Control ModeType: TEXTCurrent: 0/main/settings/capturetargetLabel: Capture TargetType: RADIOCurrent: Internal RAMChoice: 0 Internal RAMChoice: 1 Memory card
利用这些可以设置相机,比如上面的 /main/settings/capturetarget 的类型是 RADIO,二选一。
那么,设置照片保存在 RAM 上就可以:gphoto2 --set-config /main/settings/capturetarget=0。
其他参数也是这样设置。