Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
공백 변경 숨기기
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
텍스트 스타일
모양 변경
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 Diffchecker를 사용하는 방법. 데스크톱 앱을 사용하면 비교 데이터가 외부로 전송되지 않습니다!
데스크톱 앱 받기
cam12_13_diff
생성일
2년 전
비교 결과 만료 없음
초기화
내보내기
공유
설명
9 삭제
행
총
삭제
글자
총
삭제
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
139 행
복사
24 추가
행
총
추가
글자
총
추가
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
150 행
복사
import RPi.GPIO as GPIO
import RPi.GPIO as GPIO
import time, cv2
import time, cv2
from picamera2 import Picamera2, MappedArray
from picamera2 import Picamera2, MappedArray
from libcamera import Transform
from libcamera import Transform
import os
import os
import yagmail
import yagmail
복사
복사됨
복사
복사됨
email_token = os.getenv('EMAIL_TOKEN')
if not email_token:
raise ValueError("No EMAIL TOKEN found. Set the EMAIL_TOKEN environment variable.")
from_email = os.getenv('FROM_EMAIL')
if not from_email:
raise ValueError("No FROM EMAIL ACCOUNT found. Set the FROM EMAIL environment variable.")
to_email = os.getenv('TO_EMAIL')
if not to_email:
raise ValueError("No TO EMAIL ACCOUNT found. Set the TO_EMAIL environment variable.")
PIR_PIN = 4
PIR_PIN = 4
LED_PIN = 17
LED_PIN = 17
resolution = (800, 600)
resolution = (800, 600)
LOG_FILE_NAME = "/home/pi/Camera/log/photo_logs.txt"
LOG_FILE_NAME = "/home/pi/Camera/log/photo_logs.txt"
def apply_text(request):
def apply_text(request):
# Text options
# Text options
colour = (255, 255, 255)
colour = (255, 255, 255)
origin = (0, 60)
origin = (0, 60)
font = cv2.FONT_HERSHEY_SIMPLEX
font = cv2.FONT_HERSHEY_SIMPLEX
scale = 1
scale = 1
thickness = 1
thickness = 1
# text = "17082024 09:07"
# text = "17082024 09:07"
# Get the current time in the format "DDMMYYYY HH:MM"
# Get the current time in the format "DDMMYYYY HH:MM"
text = time.strftime("%d%m%Y %H:%M")
text = time.strftime("%d%m%Y %H:%M")
# Calculate the text size
# Calculate the text size
text_size, _ = cv2.getTextSize(text, font, scale, thickness)
text_size, _ = cv2.getTextSize(text, font, scale, thickness)
# Calculate the bottom-right origin
# Calculate the bottom-right origin
x = resolution[0] - text_size[0] - 10 # 10 pixels padding from the right
x = resolution[0] - text_size[0] - 10 # 10 pixels padding from the right
y = resolution[1] - 10 # 10 pixels padding from the bottom
y = resolution[1] - 10 # 10 pixels padding from the bottom
origin = (x, y)
origin = (x, y)
with MappedArray(request, "main") as m:
with MappedArray(request, "main") as m:
cv2.putText(m.array, text, origin, font, scale, colour, thickness)
cv2.putText(m.array, text, origin, font, scale, colour, thickness)
복사
복사됨
복사
복사됨
def take_photo(
picam2):
def take_photo(
_
picam2):
# Ensure the directory exists
# Ensure the directory exists
if not os.path.exists("/home/pi/Camera"):
if not os.path.exists("/home/pi/Camera"):
os.makedirs("/home/pi/Camera")
os.makedirs("/home/pi/Camera")
file_name = "/home/pi/Camera/img_" + str(time.time()) + ".jpg"
file_name = "/home/pi/Camera/img_" + str(time.time()) + ".jpg"
# picam2.capture_file(file_name)
# picam2.capture_file(file_name)
복사
복사됨
복사
복사됨
picam2.switch_mode_and_capture_file(capture_config, file_name)
_
picam2.switch_mode_and_capture_file(capture_config, file_name)
print(f"Photo saved: {file_name}")
print(f"Photo saved: {file_name}")
return file_name
return file_name
# Ensure that the directory exists before attempting to write to the log file
# Ensure that the directory exists before attempting to write to the log file
복사
복사됨
복사
복사됨
def update_photo_log_file(
photo_file_name):
def update_photo_log_file(
_
photo_file_name):
# Ensure the directory exists
# Ensure the directory exists
log_directory = os.path.dirname(LOG_FILE_NAME)
log_directory = os.path.dirname(LOG_FILE_NAME)
if not os.path.exists(log_directory):
if not os.path.exists(log_directory):
os.makedirs(log_directory)
os.makedirs(log_directory)
복사
복사됨
복사
복사됨
with open(LOG_FILE_NAME, "a"
) as f:
with open(LOG_FILE_NAME, "a"
, encoding="utf-8"
) as f:
f.write(
photo_file_name)
f.write(
_
photo_file_name)
f.write("\n")
f.write("\n")
def send_email_with_photo(yagmail_client, file_name):
def send_email_with_photo(yagmail_client, file_name):
복사
복사됨
복사
복사됨
yagmail_client.send(to=
"giljr.2009@g
mail
.com"
,
yagmail_client.send(to=
to_e
mail
,
subject="Movement detected!",
subject="Movement detected!",
contents="Here's a photo taken by your Raspberry Pi",
contents="Here's a photo taken by your Raspberry Pi",
attachments=file_name)
attachments=file_name)
복사
복사됨
복사
복사됨
# Setup camera
# Setup camera
picam2 = Picamera2()
picam2 = Picamera2()
# picam2.configure(picam2.create_still_configuration(transform=Transform(rotation=180)))
# picam2.configure(picam2.create_still_configuration(transform=Transform(rotation=180)))
# Create two separate configs - one for preview and one for capture.
# Create two separate configs - one for preview and one for capture.
# Make sure the preview is the same resolution as the capture, to make
# Make sure the preview is the same resolution as the capture, to make
# sure the overlay stays the same size
# sure the overlay stays the same size
capture_config = picam2.create_still_configuration({"size": resolution}, transform=Transform(hflip=True, vflip=True))
capture_config = picam2.create_still_configuration({"size": resolution}, transform=Transform(hflip=True, vflip=True))
preview_config = picam2.create_preview_configuration({"size": resolution}, transform=Transform(hflip=True, vflip=True))
preview_config = picam2.create_preview_configuration({"size": resolution}, transform=Transform(hflip=True, vflip=True))
# Set the current config as the preview config
# Set the current config as the preview config
picam2.configure(preview_config)
picam2.configure(preview_config)
# Add the timestamp
# Add the timestamp
picam2.pre_callback = apply_text
picam2.pre_callback = apply_text
# Start the camera
# Start the camera
picam2.start(show_preview=False)
picam2.start(show_preview=False)
picam2.start() # Start the camera
picam2.start() # Start the camera
# Pause for 2 seconds to allow the camera to stabilize
# Pause for 2 seconds to allow the camera to stabilize
time.sleep(2)
time.sleep(2)
print("Camera setup ok.")
print("Camera setup ok.")
# Remove log file
# Remove log file
if os.path.exists(LOG_FILE_NAME):
if os.path.exists(LOG_FILE_NAME):
os.remove(LOG_FILE_NAME)
os.remove(LOG_FILE_NAME)
print("Log file removed.")
print("Log file removed.")
# Setup yagmail
# Setup yagmail
복사
복사됨
복사
복사됨
password =
"ogof orem rzqf dppx"
password =
email_
token
#with open("/home/pi/.local/share/.
email_
password", "r") as f:
yag = yagmail.SMTP(
from_e
mail
, password)
# password = f.read()
yag = yagmail.SMTP(
"giljr.2009@g
mail
.com"
, password)
print("Email sender setup OK.")
print("Email sender setup OK.")
# Setup GPIOs
# Setup GPIOs
GPIO.setmode(GPIO.BCM)
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR_PIN, GPIO.IN)
GPIO.setup(PIR_PIN, GPIO.IN)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.output(LED_PIN, GPIO.LOW)
GPIO.output(LED_PIN, GPIO.LOW)
print("GPIOs setup ok.")
print("GPIOs setup ok.")
MOV_DETECT_THRESHOLD = 3.0 # Time threshold for sustained motion
MOV_DETECT_THRESHOLD = 3.0 # Time threshold for sustained motion
MIN_DURATION_BETWEEN_PHOTOS = 60.0 # Minimum time between two photos (in seconds)
MIN_DURATION_BETWEEN_PHOTOS = 60.0 # Minimum time between two photos (in seconds)
last_pir_state = GPIO.input(PIR_PIN)
last_pir_state = GPIO.input(PIR_PIN)
movement_timer = time.time()
movement_timer = time.time()
last_time_photo_taken = 0 # Initialize last photo time to 0
last_time_photo_taken = 0 # Initialize last photo time to 0
print("Everything has been set up.")
print("Everything has been set up.")
try:
try:
while True:
while True:
time.sleep(0.01)
time.sleep(0.01)
pir_state = GPIO.input(PIR_PIN)
pir_state = GPIO.input(PIR_PIN)
# Activate LED when movement is detected.
# Activate LED when movement is detected.
GPIO.output(LED_PIN, GPIO.HIGH if pir_state == GPIO.HIGH else GPIO.LOW)
GPIO.output(LED_PIN, GPIO.HIGH if pir_state == GPIO.HIGH else GPIO.LOW)
# Detecting the start of motion
# Detecting the start of motion
if last_pir_state == GPIO.LOW and pir_state == GPIO.HIGH:
if last_pir_state == GPIO.LOW and pir_state == GPIO.HIGH:
movement_timer = time.time()
movement_timer = time.time()
# Sustained motion detection
# Sustained motion detection
if last_pir_state == GPIO.HIGH and pir_state == GPIO.HIGH:
if last_pir_state == GPIO.HIGH and pir_state == GPIO.HIGH:
if time.time() - movement_timer > MOV_DETECT_THRESHOLD:
if time.time() - movement_timer > MOV_DETECT_THRESHOLD:
# Check if enough time has passed since the last photo
# Check if enough time has passed since the last photo
if time.time() - last_time_photo_taken > MIN_DURATION_BETWEEN_PHOTOS:
if time.time() - last_time_photo_taken > MIN_DURATION_BETWEEN_PHOTOS:
print("Take Photo and Send it by Email")
print("Take Photo and Send it by Email")
photo_file_name = take_photo(picam2)
photo_file_name = take_photo(picam2)
update_photo_log_file(photo_file_name)
update_photo_log_file(photo_file_name)
send_email_with_photo(yag, photo_file_name)
send_email_with_photo(yag, photo_file_name)
복사
복사됨
복사
복사됨
last_time_photo_taken =
time.time(
) # Update the last photo taken time
last_time_photo_taken =
int(
time.time(
)
) # Update the last photo taken time
last_pir_state = pir_state
last_pir_state = pir_state
except KeyboardInterrupt:
except KeyboardInterrupt:
GPIO.cleanup()
GPIO.cleanup()
picam2.stop()
picam2.stop()
저장된 비교 결과
원본
파일 열기
import RPi.GPIO as GPIO import time, cv2 from picamera2 import Picamera2, MappedArray from libcamera import Transform import os import yagmail PIR_PIN = 4 LED_PIN = 17 resolution = (800, 600) LOG_FILE_NAME = "/home/pi/Camera/log/photo_logs.txt" def apply_text(request): # Text options colour = (255, 255, 255) origin = (0, 60) font = cv2.FONT_HERSHEY_SIMPLEX scale = 1 thickness = 1 # text = "17082024 09:07" # Get the current time in the format "DDMMYYYY HH:MM" text = time.strftime("%d%m%Y %H:%M") # Calculate the text size text_size, _ = cv2.getTextSize(text, font, scale, thickness) # Calculate the bottom-right origin x = resolution[0] - text_size[0] - 10 # 10 pixels padding from the right y = resolution[1] - 10 # 10 pixels padding from the bottom origin = (x, y) with MappedArray(request, "main") as m: cv2.putText(m.array, text, origin, font, scale, colour, thickness) def take_photo(picam2): # Ensure the directory exists if not os.path.exists("/home/pi/Camera"): os.makedirs("/home/pi/Camera") file_name = "/home/pi/Camera/img_" + str(time.time()) + ".jpg" # picam2.capture_file(file_name) picam2.switch_mode_and_capture_file(capture_config, file_name) print(f"Photo saved: {file_name}") return file_name # Ensure that the directory exists before attempting to write to the log file def update_photo_log_file(photo_file_name): # Ensure the directory exists log_directory = os.path.dirname(LOG_FILE_NAME) if not os.path.exists(log_directory): os.makedirs(log_directory) with open(LOG_FILE_NAME, "a") as f: f.write(photo_file_name) f.write("\n") def send_email_with_photo(yagmail_client, file_name): yagmail_client.send(to="giljr.2009@gmail.com", subject="Movement detected!", contents="Here's a photo taken by your Raspberry Pi", attachments=file_name) # Setup camera picam2 = Picamera2() # picam2.configure(picam2.create_still_configuration(transform=Transform(rotation=180))) # Create two separate configs - one for preview and one for capture. # Make sure the preview is the same resolution as the capture, to make # sure the overlay stays the same size capture_config = picam2.create_still_configuration({"size": resolution}, transform=Transform(hflip=True, vflip=True)) preview_config = picam2.create_preview_configuration({"size": resolution}, transform=Transform(hflip=True, vflip=True)) # Set the current config as the preview config picam2.configure(preview_config) # Add the timestamp picam2.pre_callback = apply_text # Start the camera picam2.start(show_preview=False) picam2.start() # Start the camera # Pause for 2 seconds to allow the camera to stabilize time.sleep(2) print("Camera setup ok.") # Remove log file if os.path.exists(LOG_FILE_NAME): os.remove(LOG_FILE_NAME) print("Log file removed.") # Setup yagmail password = "ogof orem rzqf dppx" #with open("/home/pi/.local/share/.email_password", "r") as f: # password = f.read() yag = yagmail.SMTP("giljr.2009@gmail.com", password) print("Email sender setup OK.") # Setup GPIOs GPIO.setmode(GPIO.BCM) GPIO.setup(PIR_PIN, GPIO.IN) GPIO.setup(LED_PIN, GPIO.OUT) GPIO.output(LED_PIN, GPIO.LOW) print("GPIOs setup ok.") MOV_DETECT_THRESHOLD = 3.0 # Time threshold for sustained motion MIN_DURATION_BETWEEN_PHOTOS = 60.0 # Minimum time between two photos (in seconds) last_pir_state = GPIO.input(PIR_PIN) movement_timer = time.time() last_time_photo_taken = 0 # Initialize last photo time to 0 print("Everything has been set up.") try: while True: time.sleep(0.01) pir_state = GPIO.input(PIR_PIN) # Activate LED when movement is detected. GPIO.output(LED_PIN, GPIO.HIGH if pir_state == GPIO.HIGH else GPIO.LOW) # Detecting the start of motion if last_pir_state == GPIO.LOW and pir_state == GPIO.HIGH: movement_timer = time.time() # Sustained motion detection if last_pir_state == GPIO.HIGH and pir_state == GPIO.HIGH: if time.time() - movement_timer > MOV_DETECT_THRESHOLD: # Check if enough time has passed since the last photo if time.time() - last_time_photo_taken > MIN_DURATION_BETWEEN_PHOTOS: print("Take Photo and Send it by Email") photo_file_name = take_photo(picam2) update_photo_log_file(photo_file_name) send_email_with_photo(yag, photo_file_name) last_time_photo_taken = time.time() # Update the last photo taken time last_pir_state = pir_state except KeyboardInterrupt: GPIO.cleanup() picam2.stop()
수정본
파일 열기
import RPi.GPIO as GPIO import time, cv2 from picamera2 import Picamera2, MappedArray from libcamera import Transform import os import yagmail email_token = os.getenv('EMAIL_TOKEN') if not email_token: raise ValueError("No EMAIL TOKEN found. Set the EMAIL_TOKEN environment variable.") from_email = os.getenv('FROM_EMAIL') if not from_email: raise ValueError("No FROM EMAIL ACCOUNT found. Set the FROM EMAIL environment variable.") to_email = os.getenv('TO_EMAIL') if not to_email: raise ValueError("No TO EMAIL ACCOUNT found. Set the TO_EMAIL environment variable.") PIR_PIN = 4 LED_PIN = 17 resolution = (800, 600) LOG_FILE_NAME = "/home/pi/Camera/log/photo_logs.txt" def apply_text(request): # Text options colour = (255, 255, 255) origin = (0, 60) font = cv2.FONT_HERSHEY_SIMPLEX scale = 1 thickness = 1 # text = "17082024 09:07" # Get the current time in the format "DDMMYYYY HH:MM" text = time.strftime("%d%m%Y %H:%M") # Calculate the text size text_size, _ = cv2.getTextSize(text, font, scale, thickness) # Calculate the bottom-right origin x = resolution[0] - text_size[0] - 10 # 10 pixels padding from the right y = resolution[1] - 10 # 10 pixels padding from the bottom origin = (x, y) with MappedArray(request, "main") as m: cv2.putText(m.array, text, origin, font, scale, colour, thickness) def take_photo(_picam2): # Ensure the directory exists if not os.path.exists("/home/pi/Camera"): os.makedirs("/home/pi/Camera") file_name = "/home/pi/Camera/img_" + str(time.time()) + ".jpg" # picam2.capture_file(file_name) _picam2.switch_mode_and_capture_file(capture_config, file_name) print(f"Photo saved: {file_name}") return file_name # Ensure that the directory exists before attempting to write to the log file def update_photo_log_file(_photo_file_name): # Ensure the directory exists log_directory = os.path.dirname(LOG_FILE_NAME) if not os.path.exists(log_directory): os.makedirs(log_directory) with open(LOG_FILE_NAME, "a", encoding="utf-8") as f: f.write(_photo_file_name) f.write("\n") def send_email_with_photo(yagmail_client, file_name): yagmail_client.send(to= to_email, subject="Movement detected!", contents="Here's a photo taken by your Raspberry Pi", attachments=file_name) # Setup camera picam2 = Picamera2() # picam2.configure(picam2.create_still_configuration(transform=Transform(rotation=180))) # Create two separate configs - one for preview and one for capture. # Make sure the preview is the same resolution as the capture, to make # sure the overlay stays the same size capture_config = picam2.create_still_configuration({"size": resolution}, transform=Transform(hflip=True, vflip=True)) preview_config = picam2.create_preview_configuration({"size": resolution}, transform=Transform(hflip=True, vflip=True)) # Set the current config as the preview config picam2.configure(preview_config) # Add the timestamp picam2.pre_callback = apply_text # Start the camera picam2.start(show_preview=False) picam2.start() # Start the camera # Pause for 2 seconds to allow the camera to stabilize time.sleep(2) print("Camera setup ok.") # Remove log file if os.path.exists(LOG_FILE_NAME): os.remove(LOG_FILE_NAME) print("Log file removed.") # Setup yagmail password = email_token yag = yagmail.SMTP(from_email, password) print("Email sender setup OK.") # Setup GPIOs GPIO.setmode(GPIO.BCM) GPIO.setup(PIR_PIN, GPIO.IN) GPIO.setup(LED_PIN, GPIO.OUT) GPIO.output(LED_PIN, GPIO.LOW) print("GPIOs setup ok.") MOV_DETECT_THRESHOLD = 3.0 # Time threshold for sustained motion MIN_DURATION_BETWEEN_PHOTOS = 60.0 # Minimum time between two photos (in seconds) last_pir_state = GPIO.input(PIR_PIN) movement_timer = time.time() last_time_photo_taken = 0 # Initialize last photo time to 0 print("Everything has been set up.") try: while True: time.sleep(0.01) pir_state = GPIO.input(PIR_PIN) # Activate LED when movement is detected. GPIO.output(LED_PIN, GPIO.HIGH if pir_state == GPIO.HIGH else GPIO.LOW) # Detecting the start of motion if last_pir_state == GPIO.LOW and pir_state == GPIO.HIGH: movement_timer = time.time() # Sustained motion detection if last_pir_state == GPIO.HIGH and pir_state == GPIO.HIGH: if time.time() - movement_timer > MOV_DETECT_THRESHOLD: # Check if enough time has passed since the last photo if time.time() - last_time_photo_taken > MIN_DURATION_BETWEEN_PHOTOS: print("Take Photo and Send it by Email") photo_file_name = take_photo(picam2) update_photo_log_file(photo_file_name) send_email_with_photo(yag, photo_file_name) last_time_photo_taken = int(time.time()) # Update the last photo taken time last_pir_state = pir_state except KeyboardInterrupt: GPIO.cleanup() picam2.stop()
비교하기