Welcome to PrinterStop
Sales, Servcies and Supplies
Printers and Plotters
import cv2 import requests import time from datetime import datetime # Configuration variables TOKEN = "YOUR_TELEGRAM_BOT_TOKEN" CHAT_ID = "YOUR_TELEGRAM_CHAT_ID" # Replace with your camera's actual RTSP URL stream RTSP_URL = "rtsp://admin:password@1192.168.1.100:554/stream1" def send_telegram_alert(photo_path, caption_text): """Sends a photo alert with a text caption to the specified Telegram chat.""" url = f"https://telegram.orgTOKEN/sendPhoto" with open(photo_path, 'rb') as photo: files = 'photo': photo data = 'chat_id': CHAT_ID, 'caption': caption_text response = requests.post(url, files=files, data=data) return response.json() def main(): # Initialize video capture from RTSP stream cap = cv2.VideoCapture(RTSP_URL) if not cap.isOpened(): print("Error: Could not connect to the IP camera RTSP stream.") return print("Successfully connected to IP Camera. Monitoring for motion...") # Read initial frames to calibrate motion detection ret, frame1 = cap.read() ret, frame2 = cap.read() last_alert_time = 0 COOLDOWN_PERIOD = 30 # Seconds to wait between sending alerts while cap.isOpened(): if not ret: break # Calculate absolute difference between consecutive frames diff = cv2.absdiff(frame1, frame2) gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(gray, (5, 5), 0) _, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY) dilated = cv2.dilate(thresh, None, iterations=3) contours, _ = cv2.findContours(dilated, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) for contour in contours: # Adjust the contour area threshold based on camera environment if cv2.contourArea(contour) < 5000: continue current_time = time.time() if current_time - last_alert_time > COOLDOWN_PERIOD: timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") filename = f"motion_alert_int(current_time).jpg" # Save the frame where substantial motion was detected cv2.imwrite(filename, frame2) print(f"[timestamp] Motion detected! Triggering alert...") # Send to Telegram asynchronously/via request caption = f"⚠️ Motion Alert! \nTime: timestamp\nCamera: Main Entrance" send_telegram_alert(filename, caption) last_alert_time = current_time # Update frame sequence frame1 = frame2 ret, frame2 = cap.read() # Artificial delay to mimic frame rates without overwhelming CPU time.sleep(0.05) cap.release() if __name__ == "__main__": main() Use code with caution. 5. Security and Optimizations
The bot needs to know where to send the video. It needs your unique Chat ID. Search for on Telegram. Start a chat with it. It will reply with your ID number. Write this number down. Step 4: Generate the QR Code
Telegram uses special tools called bots to talk to cameras. You need to create your own bot. Open the Telegram app. Search for the user . Type /newbot in the chat. Give your bot a fun name. Give your bot a username that ends in "bot".
Setting up an IP camera with Telegram using a QR code generally refers to two distinct processes: connecting the camera to its own mobile app for remote viewing or linking the camera system to a Telegram bot for instant motion alerts and snapshots 1. Connecting the Camera to its App via QR
Download @BotFather , grab your camera’s RTSP URL, and build your own Telegram CCTV room today.
: Focuses on using the ultra-low-cost ESP32-CAM to capture images upon motion detection and send them to Telegram, ensuring portable and cheap surveillance.
the Telegram app (e.g., to join a security group or add a bot): Dummies Guide to Remote Viewing an IP Security Camera
Basic motion detection can be triggered by shifting shadows, wind blowing through trees, or flying insects. To fix this: