mirror of https://github.com/Askill/SurvBot.git
added docs and silght refactor
This commit is contained in:
parent
d4c5639113
commit
38d3cb3694
|
|
@ -8,3 +8,5 @@ __pycache__/
|
|||
.vscode/
|
||||
|
||||
config copy.py
|
||||
|
||||
app/imgs/
|
||||
|
|
|
|||
24
README.md
24
README.md
|
|
@ -6,20 +6,28 @@ It can be enabled/disabled via chat commands ("/start", "/stop")
|
|||
- video feed
|
||||
- server
|
||||
- telegram bot
|
||||
- tls endpoint
|
||||
- tls endpoint (optional)
|
||||
|
||||
|
||||
#### Start
|
||||
- rename img to imgs
|
||||
- rename data1.json to data.json
|
||||
- insert token + key into data.json
|
||||
#### Quick Start
|
||||
- insert bot-token + chat-key into config.py
|
||||
- change config.py to your requirements
|
||||
- pip install -r requirements.txt
|
||||
- python app.py
|
||||
|
||||
#### Docker
|
||||
#### Docker Deployment
|
||||
docker build -t survbot .
|
||||
docker run -d --rm -p 80:5003 survbot
|
||||
|
||||
#### Result:
|
||||

|
||||

|
||||
|
||||
|
||||
#### How it works
|
||||
|
||||
The image is scaled down and blured, then the difference to an earlier frame is calculated.
|
||||
The resulting frame is binarized. Then all contours are marked if they contain a number of changed pixels between the upper and lower bound specified in config.py.
|
||||
|
||||
Those contours are then marked in the original image, which is then saved in the filesystem and sent to the specified telegram bot.
|
||||
|
||||
|
||||

|
||||
|
|
@ -4,25 +4,18 @@ import config
|
|||
import time
|
||||
import cv2
|
||||
|
||||
login = config.loginPath
|
||||
loginDataJson = {}
|
||||
config.token
|
||||
config.chat_id
|
||||
|
||||
def saveImage(img):
|
||||
name = '{}'.format(int(time.time()))
|
||||
name = '{}'.format(time.time()).split(".")[0]
|
||||
path = config.photos + name + '.png'
|
||||
cv2.imwrite(path, img)
|
||||
return path
|
||||
|
||||
def notify(path):
|
||||
global loginDataJson
|
||||
photo = open(path, "rb")
|
||||
json1 = {"chat_id": config.chat_id}
|
||||
files = {'photo': photo}
|
||||
print(requests.post("https://api.telegram.org/bot" + config.token + "/sendPhoto", json1, files=files))
|
||||
|
||||
|
||||
def initEndpoint():
|
||||
tp = "http://api.telegram.org/bot" + config.token + "/setWebHook?url=" + config.endpoint
|
||||
requests.get(tp)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
monitor = True
|
||||
stream = "http://192.168.178.56:8080/video"
|
||||
photos = "./imgs/"
|
||||
|
||||
min_area = 3000
|
||||
max_area = 10000
|
||||
threashold = 18
|
||||
delay = .3
|
||||
framerate = 30
|
||||
|
||||
endpoint = ""
|
||||
token = ""
|
||||
chat_id = ""
|
||||
|
|
@ -9,17 +9,19 @@ import config
|
|||
import traceback
|
||||
import _thread
|
||||
|
||||
|
||||
|
||||
def compare():
|
||||
try:
|
||||
url = config.stream
|
||||
|
||||
min_area = 3000
|
||||
max_area = 10000
|
||||
min_area = config.min_area
|
||||
max_area = config.max_area
|
||||
|
||||
counter = 0
|
||||
threashold = 18
|
||||
delay = .3
|
||||
framerate = 30
|
||||
threashold = config.threashold
|
||||
delay = config.delay
|
||||
framerate = config.framerate
|
||||
|
||||
# initialize the first frame in the video stream
|
||||
vs = cv2.VideoCapture(url)
|
||||
|
|
@ -39,6 +41,9 @@ def compare():
|
|||
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
gray = cv2.GaussianBlur(gray, (31, 31), 0)
|
||||
|
||||
cv2.imshow("frame", frame)
|
||||
cv2.imshow("gray", gray)
|
||||
|
||||
# if the first frame is None, initialize it
|
||||
if firstFrame is None:
|
||||
firstFrame = gray
|
||||
|
|
@ -69,8 +74,8 @@ def compare():
|
|||
img = frame
|
||||
location = com.saveImage(img)
|
||||
_thread.start_new_thread(com.notify, (location, ) )
|
||||
#com.notify(location)
|
||||
|
||||
# get new image to compare to every so often to avoid changes over time ie. sun
|
||||
counter+=1
|
||||
if counter % (framerate * delay) == 0:
|
||||
firstFrame = gray
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
monitor = True
|
||||
loginPath = "./data.json"
|
||||
stream = "http://192.168.178.56:8080/video"
|
||||
photos = "./imgs/"
|
||||
endpoint = "https://telegram-bot.jopa.dev"
|
||||
token = ""
|
||||
chat_id = ""
|
||||
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 133 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 95 KiB |
Loading…
Reference in New Issue