@gnat-xj
2015-11-17T02:31:52.000000Z
字数 4118
阅读 3757
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
,即可拍一张照片。
参考这篇文章:
# deps
sudo 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
# source
wget http://sourceforge.net/projects/gphoto/files/libgphoto/2.5.2/libgphoto2-2.5.2.tar.gz
wget http://sourceforge.net/projects/gphoto/files/gphoto/2.5.2/gphoto2-2.5.2.tar.gz
# unzip, ./configure, make, make install
#/bin/bash
gphoto2 \
--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 $FOLDER
echo @___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 Corporation
Model: D7100
Version: V1.01
Serial Number: 61778820000000000000000000000000
Vendor Extension ID: 0xa (1.0)
Vendor Extension Description: microsoft.com: 1.0
Capture Formats: JPEG Undefined Type
Display Formats: Undefined Type, Association/Directory, Script, DPOF, Apple Quicktime, JPEG
Device Capabilities:
File Download, File Deletion, File Upload
Generic Image Capture, No Open Capture, Nikon Capture 1, Nikon Capture 2, Nikon Capture 3
list-all-config
( <= 点击查看全部内容)
/main/actions/autofocusdrive
Label: Drive Nikon DSLR Autofocus
Type: TOGGLE
Current: 0
/main/actions/manualfocusdrive
Label: Drive Nikon DSLR Manual focus
Type: RANGE
Current: 0
Bottom: -32767
Top: 32767
Step: 1
/main/actions/changeafarea
Label: Set Nikon Autofocus area
Type: TEXT
Current: 0x0
/main/actions/controlmode
Label: Set Nikon Control Mode
Type: TEXT
Current: 0
/main/settings/capturetarget
Label: Capture Target
Type: RADIO
Current: Internal RAM
Choice: 0 Internal RAM
Choice: 1 Memory card
利用这些可以设置相机,比如上面的 /main/settings/capturetarget
的类型是 RADIO,二选一。
那么,设置照片保存在 RAM 上就可以:gphoto2 --set-config /main/settings/capturetarget=0
。
其他参数也是这样设置。