def detect_motion(frameCount): global vs, outputFrame, lock, motion_detected # initialize the motion detector tot frames md = MotionDetector(accumWeight=0.1) total = 0 while True: # read next frame from stream, resize, to grayscale, blur frame = vs.read() frame = imutils.resize(frame, width=400) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray = cv2.GaussianBlur(gray, (7, 7), 0) # timestamp on image timestamp = datetime.datetime.now() cv2.putText(frame, timestamp.strftime( "%A %d %B %Y %I:%M:%S%p"), (10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1) # if tot frames reached enough to construct background model, continue if total > frameCount: # detect motion = md.detect(gray) # check if motion was found if motion is not None: # draw bounding box (thresh, (minX, minY, maxX, maxY)) = motion cv2.rectangle(frame, (minX, minY), (maxX, maxY), (0, 0, 255), 2) if motion_detected is False: res = telegram_bot.telegram_bot_sendtext("motion detected: " + timestamp.strftime( "%A %d %B %Y %I:%M:%S%p")) print(res) motion_detected = True # update background model and increment total frames md.update(gray) total += 1 # acquire the lock, set output frame, release with lock: outputFrame = frame.copy()
#mengambil tinggi dan lebar dari frame (frameH, frameW) = frame.shape[:2] #crop frame pada ROI untuk dideteksi roi = frame[top:bot, right:left] #dijadikan ke grayscale gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY) #smoothing gambar dengan gaussian blur gray = cv2.GaussianBlur(gray, (7, 7), 0) #frame pertama digunakan sebagai background if numFrames < 1: md.update(gray) else: #deteksi gerakan skin = md.detect(gray) #jika ada gerakan if skin is not None: (thresh, c) = skin #gambar contour cv2.drawContours( clone, [c + (right, top)], -1, (0, 255, 0), 2 ) #draw objek skin dengan menambahkan nilai kontur ke batasan box #pengenalan dan menghitung jumlah jari terangkat fingers = gd.detect(thresh, c) if gesture is None: gesture = [1, fingers] else: #jika gesture / jumlah jari sama dengan sebelumnya if gesture[1] == fingers: