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!

Features

  • 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.

How It Works

Motion Detection

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.

Telegram Bot Integration

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.

User Management

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.

Diving Deep into the Code

1. Motion Detection with OpenCV

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.

Recommended by LinkedIn

Video Chat App with Face detection using Python and… Vivek Sharma 2 years ago
RemindSupplyChainRisks? A story about poisoning PyPI SUN DING 2 years ago
Face Detection in Python: Unlocking the Power of… Harsh Jaggi 1 year ago
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.

2. Engaging Telegram Bot API

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 telebotfrom telebot import typesimport config # Importing the config file for credentialsbot = 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.

3. User Management Dynamics

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.

Setting Up TeleSec-Cam: Your Personal Watchguard

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.

TeleSec-Cam stands as a testament to the power of open-source tools and a bit of ingenuity. Dive into the GitHub repository, explore the code, set up your own security camera system, and perhaps even contribute to the project to make TeleSec-Cam even better!

Please ⭐ the project if you liked it and leave a comment if you have any questions!

DIY Telegram Security Cam with Python! (2024)

References

Top Articles
Drag The Labels Onto The Epidermal Layers
Retro Goal Unblocked Wtf
Diario Las Americas Rentas Hialeah
UPS Paketshop: Filialen & Standorte
Cold Air Intake - High-flow, Roto-mold Tube - TOYOTA TACOMA V6-4.0
Stretchmark Camouflage Highland Park
Access-A-Ride – ACCESS NYC
Mustangps.instructure
30% OFF Jellycat Promo Code - September 2024 (*NEW*)
Fototour verlassener Fliegerhorst Schönwald [Lost Place Brandenburg]
Rochester Ny Missed Connections
Ktbs Payroll Login
FIX: Spacebar, Enter, or Backspace Not Working
What’s the Difference Between Cash Flow and Profit?
Jscc Jweb
Vichatter Gifs
Rapv Springfield Ma
Buying risk?
Animal Eye Clinic Huntersville Nc
Five Day National Weather Forecast
Arre St Wv Srj
Uky Linkblue Login
Voy Boards Miss America
Yakimacraigslist
Cta Bus Tracker 77
Walgreens Bunce Rd
Which Sentence is Punctuated Correctly?
Il Speedtest Rcn Net
Relaxed Sneak Animations
SOGo Groupware - Rechenzentrum Universität Osnabrück
Maine Racer Swap And Sell
Ultra Ball Pixelmon
How rich were the McCallisters in 'Home Alone'? Family's income unveiled
Old Peterbilt For Sale Craigslist
Arcane Odyssey Stat Reset Potion
Hisense Ht5021Kp Manual
Mohave County Jobs Craigslist
Linda Sublette Actress
Cygenoth
Why I’m Joining Flipboard
Armageddon Time Showtimes Near Cmx Daytona 12
Home Auctions - Real Estate Auctions
Craigslist Rooms For Rent In San Fernando Valley
Gw2 Support Specter
American Bully Puppies for Sale | Lancaster Puppies
Sacramentocraiglist
The top 10 takeaways from the Harris-Trump presidential debate
Puss In Boots: The Last Wish Showtimes Near Valdosta Cinemas
Home | General Store and Gas Station | Cressman's General Store | California
The Goshen News Obituary
Osrs Vorkath Combat Achievements
Latest Posts
Article information

Author: Mr. See Jast

Last Updated:

Views: 6386

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.