Skip to content

Commit a4c6224

Browse files
committed
Added click script to solve images in a folder using pinpoint in MaxIm
1 parent a9d9dc9 commit a4c6224

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

pyscope/utils/pinpoint_solve.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
import time
3+
import logging
4+
import click
5+
from win32com.client import Dispatch
6+
7+
logging.basicConfig(level=logging.INFO)
8+
logger = logging.getLogger(__name__)
9+
10+
def save_image(filepath):
11+
maxim.SaveFile(filepath, 3, False, 1)
12+
13+
def open_image(filepath):
14+
maxim.OpenFile(filepath)
15+
16+
def platesolve_image(filepath, new_filepath):
17+
open_image(filepath)
18+
maxim.PinPointSolve()
19+
try:
20+
while maxim.PinPointStatus == 3:
21+
time.sleep(0.1)
22+
if maxim.PinPointStatus == 2:
23+
logger.info('Solve successful')
24+
else:
25+
logger.info('Solve failed')
26+
maxim.PinPointStop()
27+
except Exception as e:
28+
logger.error(f'Solve failed: {e}, saving unsolved image')
29+
save_image(new_filepath)
30+
logger.info(f'Saved to {new_filepath}')
31+
32+
@click.command()
33+
@click.argument('input_dir', type=click.Path(exists=True),
34+
help="""Directory containing images to solve.""")
35+
@click.option('-o','--out-dir','output_dir', default=None, type=click.Path(),
36+
help="""Directory to save solved images to. If not specified, solved images will be saved to the same directory as the input images.""")
37+
def pinpoint_solve(input_dir, output_dir=None):
38+
if output_dir is None:
39+
output_dir = input_dir
40+
day_images = os.listdir(input_dir)
41+
day_filepaths = [os.path.join(input_dir, filename) for filename in day_images]
42+
new_filepaths = [os.path.join(output_dir, filename) for filename in day_images]
43+
44+
global maxim
45+
maxim = Dispatch("Maxim.Document")
46+
47+
# Create end_dir if it doesn't exist
48+
if not os.path.exists(output_dir):
49+
os.makedirs(output_dir)
50+
51+
for filepath, new_filepath in zip(day_filepaths, new_filepaths):
52+
platesolve_image(filepath, new_filepath)
53+
54+
if __name__ == '__main__':
55+
pinpoint_solve()

0 commit comments

Comments
 (0)