-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
61 lines (43 loc) · 1.53 KB
/
main.py
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
from picamera import PiCamera
from pathlib import Path
from argparse import ArgumentParser
import time
import logging
logging.basicConfig(
filename="{}".format(Path.home() / "logs" / "acquisition.log"),
format="%(asctime)s == PILLITUP == ACQUISITION == [%(levelname)-8s] %(message)s",
level=logging.DEBUG,
)
def get_args():
parser = ArgumentParser()
parser.add_argument("pill", help="pill name")
parser.add_argument("amount", help="how many pictures", type=int)
return parser.parse_args()
def main():
args = get_args()
logging.info("Starting acquisition for {} {} times.".format(args.pill, 200))
current_dir = Path(".")
dataset_dir = current_dir / "dataset"
if not dataset_dir.exists():
logging.debug("dataset directory doesn't exist, creating...")
dataset_dir.mkdir()
pill_dir = dataset_dir / args.pill
if not pill_dir.exists():
logging.debug("pill directory doesn't exist, creating...")
pill_dir.mkdir()
with PiCamera() as cam:
logging.info("Starting camera live preview.")
cam.start_preview()
logging.info("Starting camera sequence capture.")
cam.capture_sequence(
[
"{}".format(pill_dir / "{:d}_{}.jpg".format(int(time.time()), i))
for i in range(args.amount)
]
)
logging.info("Sequence capture done.")
logging.info("Stopping camera live preview.")
cam.stop_preview()
logging.info("Done.")
if __name__ == "__main__":
main()