Last active
April 13, 2021 09:51
-
-
Save Erol444/349dbc48ada07ddbd7599a6bbe6e1f2b to your computer and use it in GitHub Desktop.
DepthAI mono camera schedule
This file contains hidden or 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
#!/usr/bin/env python3 | |
import time | |
from pathlib import Path | |
import cv2 | |
import depthai as dai | |
import schedule | |
import time | |
# Start defining a pipeline | |
pipeline = dai.Pipeline() | |
# Define a source - mono (grayscale) camera | |
camRight = pipeline.createMonoCamera() | |
camRight.setBoardSocket(dai.CameraBoardSocket.RIGHT) | |
camRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P) | |
# Create output | |
xoutRight = pipeline.createXLinkOut() | |
xoutRight.setStreamName("right") | |
camRight.out.link(xoutRight.input) | |
# Pipeline is defined, now we can connect to the device | |
with dai.Device(pipeline) as device: | |
# Start pipeline | |
device.startPipeline() | |
# Output queue will be used to get the grayscale frames from the output defined above | |
qRight = device.getOutputQueue(name="right", maxSize=1, blocking=False) | |
# Make sure the destination path is present before starting to store the examples | |
Path('07_data').mkdir(parents=True, exist_ok=True) | |
def save_img(): | |
inRight = qRight.get() # Blocking call, will wait until a new data has arrived | |
# Data is originally represented as a flat 1D array, it needs to be converted into HxW form | |
frameRight = inRight.getCvFrame() | |
# Frame is transformed and ready to be shown | |
cv2.imshow("right", frameRight) | |
# After showing the frame, it's being stored inside a target directory as a PNG image | |
cv2.imwrite(f"07_data/{int(time.time() * 10000)}.png", frameRight) | |
# Schedule the save_img function | |
schedule.every(1).hour.do(save_img) | |
while True: | |
schedule.run_pending() | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment