-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add image capturing script for picamera (#5)
* add image capturing script for picamera * linter fix * fix bug and add more details in comment * update foramtting and documentation * add picamera test utility script * Update docstring on venv instructions * linter fixes, disable invalid-name * move rc.local instructions from confluence to rc.local.copyme * Fixup test_picam_settings.py * Move rc.local commands to script file * add comments and format picam.sh * Move log directory creation into main function
- Loading branch information
Showing
5 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Taking images with a Raspberry pi camera module 3 on a Rpi on the drone. | ||
""" | ||
|
||
import pathlib | ||
import time | ||
|
||
import picamera2 | ||
|
||
|
||
LOG_DIRECTORY_PATH = pathlib.Path("logs") | ||
SAVE_PREFIX = str(pathlib.Path(LOG_DIRECTORY_PATH, "image_" + str(int(time.time())) + "_")) | ||
DELAY = 1.0 # seconds | ||
|
||
|
||
def main() -> None: | ||
""" | ||
Main loop for capturing and saving images. | ||
""" | ||
LOG_DIRECTORY_PATH.mkdir(parents=True, exist_ok=True) | ||
|
||
picam2 = picamera2.Picamera2() | ||
picam2.start(show_preview=False) | ||
|
||
name_counter = 0 | ||
while True: | ||
picam2.capture_file(f"{SAVE_PREFIX}{name_counter}.png") | ||
name_counter += 1 | ||
|
||
time.sleep(DELAY) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
# Get current Unix time to avoid collision | ||
# TODO: Something more sophisticated (e.g. counter) | ||
TIME="${date +%s}" | ||
echo $TIME | ||
|
||
# Picamera Python | ||
cd /home/warg/image-collection # Update to actual path | ||
touch logs/record_$TIME.log # To confirm script has run | ||
source venv/bin/activate | ||
python picam.py & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Utility script to test different picamera settings (for use on a Rpi5). | ||
For available settings, see appendix C: https://datasheets.raspberrypi.com/camera/picamera2-manual.pdf | ||
""" | ||
|
||
import picamera2 | ||
|
||
|
||
if __name__ == "__main__": | ||
picam2 = picamera2.Picamera2() | ||
|
||
picam2.configure(picam2.create_preview_configuration()) | ||
|
||
# Example default settings for use with IR camera + IR filter. (only sees IR hotspot) | ||
# Don't change Brightness (artificially makes everything whiter) or Contrast (doesn't look too good) | ||
# picam2.set_controls({"ExposureTime": 250, "AnalogueGain": 64.0, "Brightness": 0.0, "Contrast": 1.0}) | ||
print(picam2.controls) | ||
|
||
picam2.start(show_preview=True) | ||
|
||
while True: | ||
# Since preview already started, it does not block preview | ||
command = input("Enter a config and value (e.g. 'ExposureTime 250'): ") | ||
|
||
input_tokens = command.split() | ||
if len(input_tokens != 2): | ||
print("Invalid input") | ||
continue | ||
|
||
config, raw_value = input_tokens | ||
value = int(raw_value) if config == "ExposureTime" else float(raw_value) | ||
|
||
picam2.set_controls({command: value}) | ||
print("New controls set") | ||
print(picam2.controls) |