使用digicamcontrol使用Python控制尼康相机?

时间:2017-04-12 00:22:34

标签: python camera usb

有人在Windows上成功完成此操作吗?我正试图命令一台数码单反相机在Windows机器上用Python通过USB拍照。或者您有更好的解决方案(我无法切换到Linux)。

2 个答案:

答案 0 :(得分:0)

Digicamcontrol有一个远程实用程序,可以控制应用程序几乎所有方面,该实用程序可以在命令提示符下运行或使用Python中的subprocess.call执行

有关实用程序命令行参数的详细信息,请检查此链接http://digicamcontrol.com/doc/userguide/remoteutil

答案 1 :(得分:0)

这是一个可行的解决方案,使用Python 3.5(通过Anaconda安装),BTW。

ISO和快门的参数是硬连线的,但如果您需要它,这应该可以帮助您。

import sys
import os
import subprocess
import datetime 

def func_TakeNikonPicture(input_filename):
    camera_command = 'C:\Program Files (x86)\digiCamControl\CameraControlCmd.exe'
    camera_command_details = '/filename ./' + input_filename + ' /capture /iso 500 /shutter 1/30 /aperture 1.8'
    print('camera details = ',camera_command_details)
    full_command=camera_command + ' ' + camera_command_details
    p = subprocess.Popen(full_command, stdout=subprocess.PIPE, universal_newlines=True, shell=False)
    (output, err) = p.communicate()  

    #This makes the wait possible
    p_status = p.wait(1)
    # print(p.stdout.readline())

    #This will give you the output of the command being executed
    print('Command output: ' + str(output))
    print('Command err: ' + str(err))

    print('done')


if(len(sys.argv) < 2):
    rawimagename = 'test.jpg'
else:   
    # sys.argv[0] is the program name, sys.argv[1] is the first file, etc.
    # need to shift this over
    files = sys.argv[1:len(sys.argv)]
    # Read the image
    rawimagename = files[0]
    if(os.path.isfile(rawimagename) is True):
        print("File exists...not overwriting.")
        sys.exit()

# Store date/time for file uniqueness
current_dt=datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
print("Current date time = " + current_dt)
rawimagename=current_dt + '_' + rawimagename

print('Name of raw image will be: ', rawimagename)

# take picture
func_TakeNikonPicture(rawimagename)