diff --git a/capture.py b/capture.py index 3432443..5264913 100644 --- a/capture.py +++ b/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) diff --git a/config.py b/config.py new file mode 100644 index 0000000..190278a --- /dev/null +++ b/config.py @@ -0,0 +1,4 @@ +TOKEN = '0' +CHAT_ID = 0 +PATH = '0' +FILE_NAME = '0' \ No newline at end of file