diff --git a/main.py b/main.py index d55e04c..5b994eb 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,8 @@ import cv2 import numpy as np -cap = cv2.VideoCapture("rtsp://192.168.1.81/vaddio-conferenceshot-eptz-stream") +cap = cv2.VideoCapture(1) +cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280) +cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720) max_count = 0 # Text @@ -10,11 +12,12 @@ org2 = (50, 90) fontScale = 1 color = (255, 0, 0) thickness = 2 - +scale = 6 while True: ret, src = cap.read() - upper_left = (int(src.shape[1]/4),int(src.shape[0]/4)) - lower_right = (int(src.shape[1]/4 + src.shape[1]/2),int(src.shape[0]/4 + src.shape[0]/2) ) + center = (int(src.shape[0]/2),int(src.shape[1]/2)) + upper_left = (int(center[1] - src.shape[1]/scale),int(center[0] - src.shape[0]/scale)) + lower_right = (int(center[1] + src.shape[1]/scale),int(center[0] + src.shape[0]/scale)) gray = cv2.cvtColor(src[upper_left[1]:lower_right[1],upper_left[0]:lower_right[0]], cv2.COLOR_BGR2GRAY) sobel = cv2.Sobel(gray, cv2.CV_8U, 1, 0, ksize=3) @@ -23,9 +26,9 @@ while True: if count > max_count: max_count = count - src = cv2.putText(src, 'Max: {}'.format(max_count), org, font, fontScale, + src = cv2.putText(src, 'Max: {}'.format(int(max_count/10000)), org, font, fontScale, color, thickness, cv2.LINE_AA) - src = cv2.putText(src, 'Current: {}'.format(count), org2, font, fontScale, + src = cv2.putText(src, 'Current: {:.2f}%'.format((count/max_count)*100 - 0.01), org2, font, fontScale, color, thickness, cv2.LINE_AA) src = cv2.rectangle(src, pt1=upper_left, pt2=lower_right, color=(36,255,12), thickness=1) cv2.imshow('tresh', thresh) @@ -35,3 +38,5 @@ while True: k = cv2.waitKey(10) if k == 27: break + elif k == 32: + max_count = 0