Skip to content

Commit

Permalink
updated deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
tb-dhk committed Jul 2, 2024
1 parent ef71bd8 commit edeb15a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions bin/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,45 @@ def monitor_weight():
prev_weight = get_weight()
time.sleep(1) # Initial delay to allow for any transient readings
log_message("\nWaiting for weight change...")

while True:
log_message(f"\rWaiting for weight change (now {prev_weight/17145})...")
current_weight = get_weight()

if abs(current_weight - prev_weight) > 0.01: # Adjust the threshold as needed
new_pic = take_picture()
pics = get_latest_pictures("/home/pi/food-pod")

if len(pics) >= 2:
# Generate a difference image between the two latest pictures
diff_image = find_differences(pics[0], pics[1])
cv2.imwrite("/home/pi/food-pod/diff.jpg", diff_image)
detect_food("/home/pi/food-pod/diff.jpg")

# Create a copy of the second picture to overlay differences
image_with_diffs = cv2.imread(pics[1])

# Apply the difference mask to the second picture
image_with_diffs[diff_image != 0] = [0, 0, 255] # Mark differences in red (BGR format)

# Save the image with highlighted differences
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
cv2.imwrite(f"/home/pi/food-pod/{timestamp}-diff.jpg", image_with_diffs)

# Detect food based on the image with highlighted differences
detect_food(f"/home/pi/food-pod/{timestamp}-diff.jpg")
else:
# If less than two pictures are available, just detect food in the new picture
detect_food(new_pic)

prev_weight = current_weight

time.sleep(1)

# Assuming get_weight(), log_message(), take_picture(), get_latest_pictures(),
# find_differences(), and detect_food() functions are defined elsewhere.

# Example usage:
monitor_weight()

if __name__ == "__main__":
zero_scale() # Tare the scale to zero
log_message("Starting weight monitoring...\n")
Expand Down

0 comments on commit edeb15a

Please sign in to comment.