Add telegram bot

This commit is contained in:
Anna Sudnitsina 2019-08-10 14:14:15 +03:00
parent dcbc32d6dd
commit 27eb5bad95
2 changed files with 23 additions and 11 deletions

View File

@ -1,7 +1,15 @@
import os
import cv2
import time
import pandas
from datetime import datetime
import telebot
import config
bot = telebot.TeleBot(config.TOKEN)
prev_frame = None
times = []
@ -25,7 +33,6 @@ while True:
prev_frame = gray
# continue
delta_frame = cv2.absdiff(prev_frame, gray)
prev_frame = gray
thresh_delta = cv2.threshold(delta_frame, 30, 255, cv2.THRESH_BINARY)[1]
@ -37,30 +44,31 @@ while True:
if cv2.contourArea(contour) < 1000:
continue
status_new, status_old = 1, status_new
(x, y, w, h) = cv2.boundingRect(contour)
# cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 3)
# status_list.append(status)
if status_new != status_old:
times.append(datetime.now())
cv2.imwrite('media/capture{}.png'.format(counter), frame)
# times.append(datetime.now())
print("=" * 10)
file_name = config.PATH + config.FILE_NAME.format(counter)
cv2.imwrite(file_name, frame)
# send to telegram chat and rmove from disk
bot.send_photo(config.CHAT_ID, open(file_name, "rb"))
os.remove(file_name)
counter += 1
# cv2.imshow("capt", gray)
# cv2.imshow("delta", delta_frame)
# cv2.imshow("threshold", thresh_frame)
faces = face_cascade.detectMultiScale(gray,
scaleFactor=1.1,
minNeighbors=10)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=10)
# for x, y, w, h in faces:
# img = cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 3)
# print(type(faces))
# cv2.imshow("face_detector", img)
cv2.imshow('cat', only_cat)
cv2.imshow("cat", only_cat)
cv2.imshow("rectangle", frame)
key = cv2.waitKey(1)
if key==ord('q'):
if key == ord("q"): # quit
break
# print(times)
#
# for t in range(0, len(times), 2):
# df = df.append({"start": times[t], "end": times[t+1]}, ignore_index=True)

4
config.py Normal file
View File

@ -0,0 +1,4 @@
TOKEN = '0'
CHAT_ID = 0
PATH = '0'
FILE_NAME = '0'