Add telegram bot
This commit is contained in:
parent
dcbc32d6dd
commit
27eb5bad95
30
capture.py
30
capture.py
|
@ -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,42 +33,42 @@ 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]
|
||||
thresh_frame = cv2.dilate(thresh_delta, None, iterations=2)
|
||||
|
||||
(_,cnts,_) = cv2.findContours(thresh_frame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
(_, cnts, _) = cv2.findContours(thresh_frame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
print(len(cnts))
|
||||
for contour in cnts:
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user