Motion Detection Alarm System in Python
ฝัง
- เผยแพร่เมื่อ 1 มิ.ย. 2024
- In this video, we build a motion detection alarm system, which recognizes movement in Python.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine.com/books/
💻 The Algorithm Bible Book: www.neuralnine.com/books/
👕 Programming Merch: www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine.com/
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/NeuralNine
🎙 Discord: / discord
🎵 Outro Music From: www.bensound.com/
Timestamps:
(0:00) Intro
(0:11) Preview
(1:26) Coding Alarm System
(15:44) Demonstration
(18:47) Outro - วิทยาศาสตร์และเทคโนโลยี
Great presentation, detailed explanation, could not have asked for more
Dude this is awesome, i have been searching for almost same project, now i just need to alter it to meet my needs , thanks alot ❣️
Thanks man, learning so much from these videos
Thanks a lot, good presentation.
thx a lot really interesting i will try it right now
Thank you. Can you recommend a tutorial on how to set up a camera with a computer that runs this code? Appreciate your help.
You're really great 👍
Really good video
thank you , can i have a hint how select different cam and send mail?
Impressive...One!
is there a video on how to set up our IDE to look like yours?
i use this motion on my program. i increase the value of threshold.sum to 1000 and even 9999 to verify if it work but still its sensitive to movement..what should i do?
excellent video
This was great! One issue that I ran into (because I'm stupid and wasn't paying attention to what I was doing ha ha) is that the cam window has to be selected and in the foreground for the waitKey to be triggered by the key press. If the terminal is selected, it will just type the keyboard output to the terminal and do nothing.
I'm sure I'm the only idiot that did this, but just incase anyone else made the same mistake... I figured I'd save you the waitKey Google sinkhole you may end up in ha ha.
Keep up the great content, Flori!
Nice one.
can you do a soft for card (like yugioh, magic ,pokemon) that add card show on camera to database with the number of card associate? that can be really itneresting
when I write 'cv2.' it doesn't show me its options like VideoCapture(), but I write it manually and it works properly how to fix it?
works!, thanks!
Traceback (most recent call last):
File "/Users/vladimir/Desktop/Projects_TH-cam/main.py", line 36, in
difference = cv2.absdiff(frame_bw, start_frame)
cv2.error: OpenCV(4.7.0) /Users/runner/work/opencv-python/opencv-python/opencv/modules/core/src/arithm.cpp:650: error: (-209:Sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function 'arithm_op'
i'm also getting same error
I don't know if you will still reply, but I want to get a smart bulb, and then turn it to a specific color after motion is detected. I can already turn the bulb on and off using voice commands and change is color. Do you think it will be possible this way? Plus, I also wanted to ask if you could give me a bit more details about the type of cameras I can use and how I can connect them to my computer etc. I want fire cameras dey up at the same point, pointing in all four directions.
How do u add python code into bulb?
There are Python libraries for smart bulbs. You connect to the bulb over wi-fi specifying it's IP address in Python code.@@alertsByJarvis
Anyone tell me how does he opens his camera/webcam in the video ?
Thanks
Awesome Dude......
Cool
It didnt shows my webcam? My webcam light is turned on but its not showing any video
boss my winsound is not producing any sound
alarm_mode = not alarm_mode
wow this is mindblowing lol
Agree +1
I am having a prob
AttributeError: 'NoneType' object has no attribute 'shape.'
any support is appreciated
Same problem here --> frame = imutils.resize(frame, width=500)
Figured it out. Tabbing error. Duh!
@@kevinflanigan8653 Very old newbie wondering what tab position should be?
@@jamesfraser7394 I believe my problem was that I had the "key_pressed = cv2.waitKey(30)" statement and the two subsequent "if statements" indented too far to the right. Had pull the group back by one tab. I hope that helps.
Hi there
That's because your camera won't turn on, so there's no picture
Try to change this
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
for this
cap = cv2.VideoCapture(0)
I hope it helped you
How to make this work on a linux server without Qt?
This program was used in squid game Red light and green light...😅😅😅
Anyone having troubles with the opencv lib, for me it can't find the references
me too
I have errors at import cv2 and impot imutils
Bro first install in cmd
@@shenzo00ffbro source code available ? Can u share the link
Thx_.
11sec only
What is causing this...Very old inspired newbie asking.
Traceback (most recent call last):
File "/home/aladdinsane/vpyenv/detectmotion/detectmotion.py", line 21, in
start_frame = imutils.resize(start_frame, width=500)
File "/home/aladdinsane/vpyenv/detectmotion/lib/python3.10/site-packages/imutils/convenience.py", line 69, in resize
(h, w) = image.shape[:2]
AttributeError: 'NoneType' object has no attribute 'shape'
I'm sure it's not opening the cam on my MacBook so no image.
@@jamesfraser7394 Hi James
Here is the code that works on mac
You need import playsound and download some alarm ring :) enjoy
import threading
from playsound import playsound
import cv2
import imutils
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
_, start_frame = cap.read()
start_frame = imutils.resize(start_frame, width=500)
start_frame = cv2.cvtColor(start_frame, cv2.COLOR_BGR2GRAY)
start_frame = cv2.GaussianBlur(start_frame, (21,21), 0)
alarm = False
alarm_mode = False
alarm_counter = 0
def beep_alarm():
global alarm
for _ in range(5):
if not alarm_mode:
break
print('ALARM')
playsound ('/Applications/Sienna/songs/alert.wav')
alarm = False
while True:
_, frame = cap.read()
frame = imutils.resize(frame, width=500)
if alarm_mode:
frame_bw = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame_bw = cv2.GaussianBlur(frame_bw, (5, 5), 0)
difference = cv2.absdiff(frame_bw, start_frame)
threshold = cv2.threshold(difference, 25,255, cv2.THRESH_BINARY)[1]
start_frame = frame_bw
if threshold.sum() > 300:
alarm_counter += 1
else:
if alarm_counter > 0:
alarm_counter -= 1
cv2.imshow("Cam", threshold)
else:
cv2.imshow("Cam", frame)
if alarm_counter > 20:
if not alarm:
alarm = True
threading.Thread(target=beep_alarm).start()
key_pressed = cv2.waitKey(30)
if key_pressed == ord('t'):
alarm_mode = not alarm_mode
alarm_counter = 0
if key_pressed == ord('q'):
alarm_mode = False
break
cap.release()
cv2.destroyAllWindows()
@@ladislav6291 Thanks Ladislav!!!
@@jamesfraser7394 You're welcome
⥊ 55: 135
0: Good (if not good, then not zero)
1: Ethics
2: Problem-Solution
3: Consent
4: Emotion/Will
5: To Testify/To Meet
6: Why/Who/When/How/Where/What
7: Information
8: Stability
9: Sanity/Seriousness
10: Network (Good Network, because zero)
11: Justice
13: Death
16: Tower
20: Judgement
21: Solving Problems with Ethics
22: Resistance
23: Resilience
30: Good Wave
32: Discernment
33: Sacred
40: Good Force
44: Free Love
50: Good Expression
55: War
57: Counter-Terrorism
60: Good Reason
70: Good Information
80: Good Stability
90: Good Seriousness
95: Only One Global Fiat Currency
96: Blockchain
97: Anarchy
98: Vegan
99: Revolution
100: Liberation
444: Direct Digital Democracy
555: Diplomacy
1000: Possible Conversation Method using numbers to convey meaning
For ex.: 6022: Good Reason to Resist.
513