Updated README | Added AI processing to the code.

master
Matt Theissen 1 year ago
parent afcae48b57
commit a46a945c07

@ -6,10 +6,12 @@ When it finds a new image it sends it to the group.
pip install watchdog
pip install pyTelegramBotAPI
pip install opencv-python
Create a file named config_bot.py with the following variables set.
botToken
chatId
dirLoc
- botToken
- chatId
- dirLoc
- codeai_server

@ -1,33 +1,58 @@
#!/usr/bin/python3
#!/usr/bin/env python3
import cv2
import requests
import telebot
import sys
sys.path.append("bot_config")
import bot_config as i
botToken = i.botToken
bot = telebot.TeleBot(botToken)
chatId = i.chatId
dirLoc = i.dirLoc
import time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
import bot_config as i
chat_id = i.chat_id
dir_loc = i.dir_loc
bot_token = i.bot_token
codeai_server = i.codeai_server
bot = telebot.TeleBot(bot_token)
def find_human(event):
image_data = open(event.src_path, "rb").read()
response = requests.post(f"{codeai_server}/v1/vision/detection",
files={"image":image_data}).json()
for object in response["predictions"]:
if object["label"] == "person" and object["confidence"] > 0.60:
path = event.src_path
image = cv2.imread(path)
color = (0, 0, 255)
thickness = 2
image = cv2.rectangle(image, (object["x_min"], object["y_min"]), (object["x_max"], object["y_max"]), color, thickness)
cv2.imwrite(path,image)
send_telegram(event)
break
# print(response["predictions"])
def send_telegram(event):
time.sleep(1)
bot.send_photo(chat_id=chat_id, photo=open(event.src_path, 'rb'))
bot.send_message(chat_id=chat_id, text="Tweakers?!")
if __name__ == "__main__":
patterns = ["*"]
ignore_patterns = None
ignore_directories = True
case_sensitive = False
my_event_handler = PatternMatchingEventHandler(patterns, ignore_patterns, ignore_directories, case_sensitive)
my_event_handler = PatternMatchingEventHandler(
patterns=patterns,
ignore_patterns=ignore_patterns,
ignore_directories=ignore_directories,
case_sensitive=case_sensitive
)
def on_created(event):
time.sleep(1)
bot.send_photo(chat_id=chatId, photo=open(event.src_path, 'rb'))
my_event_handler.on_created = find_human
my_event_handler.on_created = on_created
path = dirLoc
path = dir_loc
go_recursively = False
my_observer = Observer()
my_observer.schedule(my_event_handler, path, recursive=go_recursively)