DIY Telegram Security Cam with Python! (2024)

Having a cozy little place, I always fancied a simple security setup that could keep an eye on my abode while I’m away. The market options were either too fancy or just didn’t hit the right chord with my tech-savvy self. So, I decided to roll up my sleeves and build my own tailored security system, TeleSec-Cam. With a dash of Python, a sprinkle of Telegram bot magic, and my trusty old webcam, I embarked on a coding adventure that not only satiated my tech cravings but also brought a sense of security to my living space. In this article, I’ll share the crests and troughs of my journey with TeleSec-Cam, unravel the code that breathes life into it, and guide you on how you too can set up your personalized security sentinel. Dive into the TeleSec-Cam’s humble abode on GitHub to get a sneak peek of the action!

  • Motion Detection: Utilizing your webcam, TeleSec-Cam continuously monitors your space for motion. If anything moves, it sends an alert to your Telegram.
  • Live Capture on Demand: With a simple command to the Telegram bot, you can receive a live capture from your webcam anytime you want.
  • User Management: Control who has access to receive alerts and request live captures through a user-friendly interface on Telegram.

TeleSec-Cam employs OpenCV, a powerful library for computer vision tasks, to access the webcam and analyze the video feed for motion. When motion is detected, it captures a frame and sends an alert to the authorized Telegram users.

The Telegram bot acts as the interface between the user and the security camera system. It sends alerts when motion is detected, provides live captures on demand, and allows for user management. All interactions with the bot are secured, ensuring only authorized users have access.

Through the bot, the admin can add or remove users who have access to the system. This is done through a simple command and username input, making user management straightforward and secure.

The heartbeat of TeleSec-Cam is its ability to detect motion. The security_cam.py script houses the logic for accessing the webcam and processing the video feed using the OpenCV library.

import cv2

# ... other imports ...

def main():
cap = cv2.VideoCapture(0) # Access the webcam
ret, frame1 = cap.read()
ret, frame2 = cap.read()

while cap.isOpened():
diff = cv2.absdiff(frame1, frame2) # Calculate absolute difference between consecutive frames
gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY) # Convert to grayscale
blur = cv2.GaussianBlur(gray, (5,5), 0) # Apply Gaussian blur
_, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY) # Thresholding
dilated = cv2.dilate(thresh, None, iterations=3) # Dilate thresholded image to fill in holes
contours, _ = cv2.findContours(dilated, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # Find contours

for contour in contours:
(x, y, w, h) = cv2.boundingRect(contour)
if cv2.contourArea(contour) < 700: # Ignore small movements
continue
cv2.rectangle(frame1, (x, y), (x+w, y+h), (0, 255, 0), 2) # Draw rectangle around moving object
# ... alert logic ...

# ... other code ...

frame1 = frame2
ret, frame2 = cap.read()

if cv2.waitKey(10) == 27:
break

cap.release()
cv2.destroyAllWindows()

if __name__ == "__main__":
main()

In this snippet, OpenCV’s cv2.VideoCapture function initializes access to the webcam. The script then enters a loop, where it reads frames from the webcam, processes them to detect motion, and triggers an alert if motion is detected.

Telegram provides a powerful bot API, which TeleSec-Cam harnesses for real-time notifications and user interaction. The telegram_bot.py script leverages the pyTelegramBotAPI library to handle incoming commands and send alerts.

import telebot
from telebot import types
import config # Importing the config file for credentials

bot = telebot.TeleBot(config.BOT_TOKEN)

# ... other code ...

@bot.message_handler(commands=['capture'])
def handle_capture_command(message):
# ... capture logic ...

# ... other code ...

if __name__ == "__main__":
bot.polling(none_stop=True)

In this segment, telebot.TeleBot initializes the bot with the token obtained from Telegram. The @bot.message_handler decorator is a straightforward way to define how the bot should respond to specific commands.

TeleSec-Cam empowers the admin to manage user access directly via the Telegram bot. The user management logic embedded within the Telegram bot script facilitates the addition or removal of authorized users.

# ... other code ...

@bot.message_handler(func=lambda message: message.text == 'Add User' and message.chat.id == config.TELEGRAM_USER_ID)
def prompt_for_username(message):
# ... add user logic ...

@bot.message_handler(func=lambda message: message.text == 'Remove User' and message.chat.id == config.TELEGRAM_USER_ID)
def prompt_for_username_to_remove(message):
# ... remove user logic ...

# ... other code ...

Here, @bot.message_handler once again comes into play, defining the behavior of the bot when the 'Add User' or 'Remove User' commands are received.

Getting TeleSec-Cam up and running involves a few simple steps: cloning the TeleSec-Cam repository, installing the required dependencies, providing your Telegram credentials, and initiating the main.py script. The README in the repository provides a detailed walkthrough to guide you through the setup process.

DIY Telegram Security Cam with Python! (2024)

References

Top Articles
Bail bondsman says scams are on the rise: "It's really costing the citizens"
Logan County Detention Center Roster Lookup, AR, Inmate Search
Wordscapes Level 5130 Answers
Pieology Nutrition Calculator Mobile
Horoscopes and Astrology by Yasmin Boland - Yahoo Lifestyle
360 Training Alcohol Final Exam Answers
Cinepacks.store
Cvs Devoted Catalog
Bustle Daily Horoscope
Natureza e Qualidade de Produtos - Gestão da Qualidade
Find your energy supplier
Es.cvs.com/Otchs/Devoted
OpenXR support for IL-2 and DCS for Windows Mixed Reality VR headsets
This Modern World Daily Kos
Dc Gas Login
Tcgplayer Store
National Office Liquidators Llc
Buff Cookie Only Fans
Crossword Nexus Solver
Colorado mayor, police respond to Trump's claims that Venezuelan gang is 'taking over'
Mile Split Fl
Metro Pcs.near Me
Busted Campbell County
Garnish For Shrimp Taco Nyt
Tips and Walkthrough: Candy Crush Level 9795
Engineering Beauties Chapter 1
Craigslist Wilkes Barre Pa Pets
Manuela Qm Only
SOGo Groupware - Rechenzentrum Universität Osnabrück
Nk 1399
Bj타리
Nearest Ups Ground Drop Off
In hunt for cartel hitmen, Texas Ranger's biggest obstacle may be the border itself (2024)
How Do Netspend Cards Work?
Willys Pickup For Sale Craigslist
Ucm Black Board
Ixlggusd
How to Play the G Chord on Guitar: A Comprehensive Guide - Breakthrough Guitar | Online Guitar Lessons
Movies123.Pick
Oreillys Federal And Evans
Midsouthshooters Supply
Stanford Medicine scientists pinpoint COVID-19 virus’s entry and exit ports inside our noses
Culver's of Whitewater, WI - W Main St
Join MileSplit to get access to the latest news, films, and events!
O'reilly's Palmyra Missouri
All-New Webkinz FAQ | WKN: Webkinz Newz
Winta Zesu Net Worth
Lady Nagant Funko Pop
Florida Lottery Powerball Double Play
Wolf Of Wallstreet 123 Movies
The Blackening Showtimes Near Ncg Cinema - Grand Blanc Trillium
Peugeot-dealer Hedin Automotive: alles onder één dak | Hedin
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 6380

Rating: 4.1 / 5 (72 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.