-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdslr.py
More file actions
120 lines (100 loc) · 3.68 KB
/
dslr.py
File metadata and controls
120 lines (100 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from time import sleep
from datetime import datetime
from sh import gphoto2 as gp
import signal, os, subprocess
from multiprocessing import Process
import threading
import json
import os
from sh import gphoto2 as gp
import subprocess
from PIL import Image
# Load configuration from config.json
with open('config.json', 'r') as f:
config = json.load(f)
eventId = config['eventId']
tema = config['tema']
def renameImage(name):
for filename in os.listdir("."):
if len(filename) < 13:
if filename.endswith("jpg"):
os.rename(filename, (name + ".jpg"))
def captureImage():
sleep(0.5)
cmd = "gphoto2 --capture-image-and-download"
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
# Wait for the command to finish and get the return code
return_code = process.wait()
def killStream():
p = subprocess.Popen([ 'ps', '-A'], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
if b'ffmpeg' in line:
# Kill the process!
pid = int (line.split(None,1) [0] )
os.kill (pid, signal.SIGKILL)
p = subprocess.Popen([ 'ps', '-A'], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
if b'gvfs-gphoto2-volume-monitor' in line:
# Kill the process!
pid = int (line.split(None,1) [0] )
os.kill (pid, signal.SIGKILL)
p = subprocess.Popen([ 'ps', '-A'], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
if b'gvfsd-gphoto2' in line:
# Kill the process!
pid = int (line.split(None,1) [0] )
os.kill (pid, signal.SIGKILL)
def resizeImage(name):
# New image size
new_size = (1500, 1000)
# Open image
image = Image.open(name)
# Get image info
exif = image.info['exif']
# resize with Lanczos method
resized_image = image.resize(new_size, resample = Image.LANCZOS)
resized_image.save(name, quality=96, exif=exif)
def shutterCounter():
killStream()
# Run the gphoto2 command
command = ["gphoto2", "--get-config", "/main/status/shuttercounter"]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
stdout, stderr = process.communicate()
# Check for errors
if process.returncode != 0:
print(f"Error: {stderr}")
return stderr
else:
# Parse the "Current" value from the output
lines = stdout.split('\n')
for line in lines:
if line.startswith("Current:"):
current_value = line.split(":")[1].strip()
print(f"Current Shutter Count: {current_value}")
return current_value
def get_camera_info():
try:
result = subprocess.run(['gphoto2', '--auto-detect'], capture_output=True, text=True, check=True)
output = result.stdout
lines = output.split('\n')
model_name = None
port = None
# Find the line with the camera model and port information
for line in lines:
if "Canon EOS" in line: # You can adjust this condition for different camera brands
info = line.split()
model_name = " ".join(info[1:])
if len(info) > 2:
port = info[-1]
if model_name is None:
model_name = "No camera detected"
if port is None:
port = "Port information not found"
#return model_name.strip(), port.strip()
return model_name.strip()
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
return "Error", e