Skip to content

Commit

Permalink
pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrhm committed Nov 10, 2024
1 parent ad8d064 commit 1db5656
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions scripts/image_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import numpy as np
import sys
import os
from pathlib import Path
import datetime

import cv2
Expand All @@ -25,14 +25,14 @@ def save_image(self, msg: Image):
img = np.frombuffer(msg.data, dtype=np.uint8).reshape(msg.height, msg.width, -1)
unique_id = "{date:%Y-%m-%d_%H:%M:%S}".format(date=datetime.datetime.now())

path = os.path.join(get_package_share_directory("mrover"), "../../../../src/mrover/data/images")
path = Path(get_package_share_directory("mrover")) / ".."/ ".." / ".." / ".." / "src" / "mrover" / "data" / "images"

if not os.path.exists(path):
os.mkdir(path)
if not path.exists():
path.mkdir(parents=True, exist_ok=True)

path = os.path.join(path, f"image_{unique_id}.jpg")
path = path / f"image_{unique_id}.jpg"

cv2.imwrite(path, img)
cv2.imwrite(str(path), img)

self.get_logger().info(f"Saved image_{unique_id}.jpg")
pass
Expand Down

0 comments on commit 1db5656

Please sign in to comment.