通过单反wifi同步照片到Android手机——使用Airnef Python脚本

前言

本人使用的是尼康D750,自带wifi功能,奈何配套的Android App太难用了,至于怎么难用,我这里就不细说了,用过的都懂。总不能白瞎了wifi功能吧。找了一阵子发现了两个第三方通过逆向工程制作的工具。一个是qDslrDashboard这个app,功能很强大,可以通过手机控制相机,也可以浏览下载相机的照片,还可以协助拍摄延时摄影。另一个就是Airnef,一个python脚本。对PC端有封装GUI。可以实现照片拷贝下载,将指定时间点之后的照片下载下来,不会重复下载已删除的照片,可以实时同步拍摄的照片。完全可以替代原厂渣渣的配套App。所以我就通过Termux搭建Python环境来运行Airnef

上面介绍的两个工具索尼和佳能带有wifi功能的相机也能使用

这样我在手机上就非常轻松的实现了同步单反中jpeg照片功能。这里简单的做一下使用介绍

1. 使用Termux搭建Python运行环境

建议安装oh-my-zsh,不想安装的可以跳过

sh -c "$(curl -fsSL https://github.com/Cabbagec/termux-ohmyzsh/raw/master/install.sh)"
pkg update
pkg install python

2. 下载解压Airnef到Android手机中

下载地址:http://www.testcams.com/airnef/Version_1.1/airnef_v1.1_Source.zip
我将脚本放在 /sdcard/scripts/airnef/airnefcmd.py

cd /sdcard
mkdir scripts
cd scripts
wget http://www.testcams.com/airnef/Version_1.1/airnef_v1.1_Source.zip
unzip airnef_v1.1_Source.zip
rm airnef_v1.1_Source.zip

3. 帮助说明

$ python /sdcard/scripts/airnef/airnefcmd.py -h 
airnef v1.1 - Wireless transfer of images/movies for Nikon cameras [GPL v3]
Copyright (c) TestCams.com, Time: 01/18/19 22:55:06, Py: 3.7.2, OS: Linux

usage: airnefcmd.py [-h] [--ipaddress addr]
                    [--action {getfiles,getsmallthumbs,getlargethumbs,listfiles}]
                    [--realtimedownload {disabled,afternormal,only}]
                    [--extlist extension [extension ...]] [--startdate date]
                    [--enddate date] [--outputdir path]
                    [--ifexists {uniquename,skip,overwrite,prompt,exit}]
                    [--downloadhistory {skipfiles,ignore,clear}]
                    [--onlyfolders camera_folder [camera_folder ...]]
                    [--excludefolders camera_folder [camera_folder ...]]
                    [--filenamespec spec] [--dirnamespec spec]
                    [--transferorder {oldestfirst,newestfirst}]
                    [--slot {firstfound,first,second,both}]
                    [--cameratransferlist {useifavail,exitifnotavail,ignore}]
                    [--downloadexec executable [arguments ...]]
                    [--downloadexec_extlist extension [extension ...]]
                    [--downloadexec_options option [option ...]]
                    [--realtimepollsecs seconds]
                    [--logginglevel {normal,verbose,debug}]

Wifi image transfer utility for Nikon cameras (airnef@hotmail.com)

optional arguments:
  -h, --help            show this help message and exit
  --ipaddress addr      IP address of camera. Default is "192.168.1.1"
  --action {getfiles,getsmallthumbs,getlargethumbs,listfiles}
                        Program action. Default is "getfiles"
  --realtimedownload {disabled,afternormal,only}
                        Download images from camera in realtime as they're
                        taken. 'afternormal' means realtime capture starts
                        after regular image download. 'only' skips normal
                        download and only captures realtime images. Default is
                        "disabled"
  --extlist extension [extension ...]
                        Type of image/file(s) to download. Ex: "--extlist
                        NEF". Multiple extensions can be specified. Use
                        "<NOEXT>" to include files that don't have extensions.
                        Default is to download all file types
  --startdate date      Only include image/file(s) captured on or later than
                        date. Date-only Ex: --startdate 12/05/14. Date+Time
                        Example: --startdate "12/05/14 15:30:00"
  --enddate date        Only include image/file(s) captured on or earlier than
                        date or date+time. Date without a specified time is
                        inclusive, so for example --enddate 06/12/14 is
                        interpreted as 06/12/14 23:59:59
  --outputdir path      Directory to store image/file(s) to. Default is
                        current directory. No ending backslash is necessary.
                        If path contains any spaces enclose it in double
                        quotes. Example: --outputdir "c:\My Documents"
  --ifexists {uniquename,skip,overwrite,prompt,exit}
                        Action to take if file with same name already exists.
                        Default is "uniquename"
  --downloadhistory {skipfiles,ignore,clear}
                        'skipfiles' means that files in history (ie,
                        previously downloaded) will be skipped and not
                        downloaded. Default is "skipfiles"
  --onlyfolders camera_folder [camera_folder ...]
                        Only include image/file(s) existing in specified
                        camera folders.. Ex: "--onlyfolders 100D7200
                        101D7200". Default is to include all folders
  --excludefolders camera_folder [camera_folder ...]
                        Exclude image/file(s) existing in specified camera
                        folders.. Ex: "--excludefolders 103D7200". Default is
                        no exclusions.
  --filenamespec spec   Optionally rename files using dynamic renaming engine.
                        See online help for documentation on 'spec'
  --dirnamespec spec    Optionally name directories using dynamic renaming
                        engine. See online help for documentation on 'spec'
  --transferorder {oldestfirst,newestfirst}
                        Transfer oldest or newest files first. Default is
                        "oldestfirst"
  --slot {firstfound,first,second,both}
                        Card slot on camera to read from. Default is
                        "firstfound", which means first populated slot
  --cameratransferlist {useifavail,exitifnotavail,ignore}
                        Decide how to handle images selected on camera.
                        Default is "useifavail"
  --downloadexec executable [arguments ...]
                        Launch application for each file downloaded
  --downloadexec_extlist extension [extension ...]
                        Type of files(s) by extension on wich to perform
                        --downloadexec on. Default is all file types
  --downloadexec_options option [option ...]
                        Options for launcing application. For example 'wait'
                        waits for launched app to exit before proceeding to
                        next download. See online help for more options
  --realtimepollsecs seconds
                        How often camera is polled for new images in realtime
                        mode, in seconds. Default is every 3 seconds
  --logginglevel {normal,verbose,debug}
                        Sets how much information is saved to the result log.
                        Default is "normal"

Options can also be specified from a file. Use !<filename>. Each word in the
file must be on its own line.

You can abbreviate any argument name provided you use enough characters to
uniquely distinguish it from other argument names.

Command-Line Examples:
  airnefcmd.py --extlist NEF MOV (download only raw images and MOV files)
  airnefcmd.py --downloadhistory ignore (dont skip files previously downloaded)

4. 使用别名简化脚本使用

~/.zshrc 文件中加入(如果不是使用zsh作为默认shell的话,则在~/.bashrc中加入)

#获取今天的日期,这里只拷贝今天的
date=`date +'%m/%d/%y'`
#实时拷贝拍摄的照片到手机
alias airnef_realtime="python /sdcard/scripts/airnef/airnefcmd.py --action getfiles --ipaddress 192.168.1.1 --realtimedownload only --logginglevel normal --extlist NEF JPG --outputdir /sdcard/DCIM/NIKON --ifexists skip --slot second --transferorder oldestfirst --cameratransferlist ignore --downloadexec sh /sdcard/scripts/airnef/previewImage.sh \"@pf@\""
#拷贝今天拍摄的照片到手机
alias airnef_copy_today="python /sdcard/scripts/airnef/airnefcmd.py --action getfiles --ipaddress 192.168.1.1 --realtimedownload disabled --logginglevel normal --extlist NEF JPG --outputdir /sdcard/DCIM/NIKON --ifexists skip --slot second --transferorder oldestfirst --startdate ${date} --cameratransferlist ignore --downloadexec sh /sdcard/scripts/airnef/scanner.sh \"@pf@\""
#拷贝所有新照片
alias airnef_copy="python /sdcard/scripts/airnef/airnefcmd.py --action getfiles --ipaddress 192.168.1.1 --realtimedownload disabled --logginglevel normal --extlist NEF JPG --outputdir /sdcard/DCIM/NIKON --ifexists skip --slot second --transferorder oldestfirst --cameratransferlist ignore --downloadexec sh /sdcard/scripts/airnef/scanner.sh \"@pf@\""
#拷贝所有新照片,并将监听实时拍摄的照片
alias airnef_copy_realtime="airnef_copy && airnef_realtime"

实现图片预览的脚本
/sdcard/scripts/airnef/previewImage.sh

#!/system/bin/sh
echo "Preview Image"
#媒体扫描
am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file://$1 > /dev/null 2>&1 &
am start -a android.intent.action.VIEW -t image/jpeg -d file://$1 > /dev/null 2>&1 &

媒体扫描脚本
/sdcard/scripts/airnef/scanner.sh

#!/system/bin/sh
am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file://$1 > /dev/null 2>&1 &

5. 使用

连接相机wifi,然后打开termux,运行命令
在这里插入图片描述

在这里插入图片描述

### 使用 Python 控制佳能单反相机 为了使用 Python 编程来控制佳能单反相机,可以借助第三方库或直接利用佳能提供的 SDK。 #### 方法一:基于佳能官方 SDK 的解决方案 佳能提供了专门针对其数码单反相机的软件开发套件 (SDK),该 SDK 支持多种编程语言,包括 C++ 和 C#。虽然 SDK 并未直接支持 Python,但可以通过调用这些底层 API 来间接实现功能[^3]。具体操作如下: - 需要先安装并配置好佳能 EDSDK(EOS Digital Software Development Kit),可以从指定链接获取最新版本。 - 利用 `ctypes` 或者 `cffi` 这样的 Python 库去加载和交互 EDSK 中定义的功能函数。 ```python import ctypes edsdk_path = r"C:\Path\To\EDSDK.dll" sdk = ctypes.windll.LoadLibrary(edsdk_path) def init_camera(): sdk.EDS_InitSDK() init_camera() ``` 这种方法的优点在于能够访问最原始且完整的硬件接口;缺点则是学习曲线较陡峭,并且可能遇到跨平台兼容性问题。 #### 方法二:采用封装好的高级库 PyEds 对于希望简化流程而不必深入研究低级细节的人来说,存在一些由社区维护的高层次抽象层——比如 PyEds 就是一个不错的选择。它已经完成了大部分繁琐的工作,使得开发者只需几行简单的命令就能完成诸如拍照、视频录制等基本任务。 ```python from pyeds import Camera with Camera() as cam: cam.take_picture() ``` 此方式更加便捷高效,适合快速原型设计或是小型项目应用场合。不过需要注意的是由于并非官方出品,在某些特定型号的支持程度上可能会有所欠缺。 #### 方法三:通过 DigicamControl 实现远程拍摄指令发送 除了上述两种途径外,还有另一种思路即借用其他成熟的图形界面应用程序作为中介桥梁来进行自动化脚本编写。例如 DigiCamControl 是一款非常受欢迎的开源软件,允许用户自定义宏动作序列并通过 COM 端口向连接设备发出相应请求。Python 可以轻松地与这类外部进程建立通信链路从而达到目的。 ```python import subprocess command = ["DigiCamControl", "/cmd=TakePicture"] subprocess.run(command, check=True) ``` 这种方式灵活性高,易于集成进现有工作流当中,但是依赖于额外的应用环境部署,增加了系统的复杂度。 综上所述,根据实际需求和个人偏好可以选择最适合自己的方案实施下去。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值