-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimagelogger.py
More file actions
86 lines (67 loc) · 2.48 KB
/
Copy pathimagelogger.py
File metadata and controls
86 lines (67 loc) · 2.48 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import cv2
import requests
import numpy as np
import datetime
from lib.logger import Logger
logger = Logger()
from config import image_url
# record images of solar panels and write the power text on it.
# source is an esp32-cam
def get_image(left,right, debug = False):
# Download the image using requests
try:
response = requests.get(image_url, timeout=0.5)
except requests.exceptions.ConnectionError as e:
logger.log(f"Image ConnectionError, {e}")
return
except requests.exceptions.Timeout:
logger.log("Image request timed out")
return
except requests.exceptions.RequestException as e:
logger.log(f"Image An error occurred:, {e}")
return
if response.status_code == 200:
# Convert the image data to a NumPy array
image_data = np.frombuffer(response.content, np.uint8)
# Read the image using OpenCV
image = cv2.imdecode(image_data, cv2.IMREAD_COLOR)
# Define the font settings
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 1
font_color = (0, 0, 255) # White color in BGR
font_thickness = 2
# Add the text to the image
cv2.putText(image, str(left), (350, 600) , font, font_scale, font_color, font_thickness) # place text here
cv2.putText(image, str(right), (700, 600), font, font_scale, font_color, font_thickness)
now = datetime.datetime.now()
text = now.strftime("%Y-%m-%d %H:%M:%S")
cv2.putText(image, text, (900, 1000), font, font_scale, font_color, font_thickness)
# Generate a filename with the format "year-month-day-hour-min-sec"
now = datetime.datetime.now()
filename = now.strftime("%Y-%m-%d_%H-%M-%S") + ".jpg"
# Save the modified image
cv2.imwrite(filename, image)
if debug:
# Display the image (optional)
cv2.imshow('Image with Text', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
print("Failed to download the image.")
if __name__ == '__main__':
get_image("ooh", "Noooo", True)
'''
mport cv2
import numpy as np
import glob
img_array = []
for filename in glob.glob('C:/New folder/Images/*.jpg'):
img = cv2.imread(filename)
height, width, layers = img.shape
size = (width,height)
img_array.append(img)
out = cv2.VideoWriter('project.avi',cv2.VideoWriter_fourcc(*'DIVX'), 15, size)
for i in range(len(img_array)):
out.write(img_array[i])
out.release()
'''