Question

In: Computer Science

Use your webcam and record a movie, write a motion detection code and print the message...

Use your webcam and record a movie, write a motion detection code and print the message "Motion Detected" on the original frame. Try to make a better visualization by using different masking.

---using Numpy and opencv

Solutions

Expert Solution

import numpy as np
import cv2 import time
sthresh = 12
fonts = cv2.font_Hershey_sim
# for facial detection, where f1 and f2 are frames
def distmp(f1, f2):"distance between two frames f1 and f2 using Pythagorean theorem"
f1_32 = np.float32(f1)
f2_32 = np.float32(f2)
d32 = f1_32 - f2_32
n32 = np.sqrt(d32[:,:,0]**2 + d32[:,:,1]**2 + d32[:,:,2]**2)/np.sqrt(255**2 + 255**2 + 255**2)
distance = np.uint8(n32*255)
return distance
cv2.named_window('frames')
cv2.named_window('distance')
#capturing video stream from web camera . 1 refers to first web camera, 2 refers second web camera
capt = cv2.video_capture(1)
_, f1 = capt.read()
_, f2 = capt.read()
face_count = 0
while(1):
_, f3 = capt.read()
rows, cols, _ = np.shape(f3)
cv2.im_show('distance', f3)
distance = distmp(f1, f3)
f1 = f2
f2 = f3
# Using Gaussian smoothing approach
mod1 = cv2.GaussBlur(distance, (9,9), 0)
# for Thresholding purpose
_, thresh1 = cv2.thhold(mod1, 100, 255, 0)
# find test stdev
_, stdv = cv2.meanstdv(mod1)
cv2.im_show('distance', mod1)
cv2.put_txt(f2, "Std deviation - {}".format(round(stdv[0][0],0)), (70, 70), font, 1, (255, 0, 255), 1, cv2.Line1_AA)
if stdv > sthresh:
print(""Motion Detected on the original frame");
# For face_detection second
cv2.im_show('frames', f2)
if cv2.wait_key(1) & 0xFF == 27:
break
capt.release()
cv2.destroy_all_windows()


Related Solutions

Write an assembly language program that will print out the message of your choosing #NOTE #write...
Write an assembly language program that will print out the message of your choosing #NOTE #write in a simple way, so that i can execute it from command window using masm
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message...
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message on console with a message like the examples. a. If the DOB you entered is in the future, print “Hello XXXXX, there are XXX days to your Birthday!” b. If the DOB you entered is today, print “Hello XXXXX, happy birthday!” c. If the DOB you entered is in the past, print “Hello XXXXX, your next birthday will be in XXX days.” d. Replace...
write code in python and test Conversation with an AI ChatBot Learning Outcomes: Use the print()...
write code in python and test Conversation with an AI ChatBot Learning Outcomes: Use the print() function to output a variety of data Use the input() function to ask for multiple data types Use basic arithmetic operations in a program Use string methods and operations Use if/else if/else statements to determine the flow of the program Comment your code Debug your code Test your code Scenario A new marketing company is launching an Artificial Intelligence (AI) ChatBot for their website...
In C++ Instructions: Use a void function to print the following message (should be in welcome...
In C++ Instructions: Use a void function to print the following message (should be in welcome function) Welcome to the Event Scheduling program create 3 int arrays with 3 positions (one array for days one array for moths and one array for years) (should be in main) Create a file that contains the following (you can just create the file or write the file in the program) 1 / 26 / 2021 12 / 13 / 2020 2 / 1...
Instructions (in C++): 1 ) Use a void function to print the following message (should be...
Instructions (in C++): 1 ) Use a void function to print the following message (should be in welcome function) Welcome to the Event Scheduling program 2 ) create 3 int arrays with 3 positions (one array for days one array for moths and one array for years) (should be in main) 3 ) Create a file that contains the following (you can just create the file or write the file in the program) 1 / 26 / 2021 12 /...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an earthquake is in the range [0, 3), “medium” if M is in the range [3, 6), “large” if M is in the range [6, 9) and “epic” if M is greater than or equal to 9, where M is input by a user via the keyboard. (in c++)
Modify the following source code so that five subsequent threads print the message “Hello World number,”...
Modify the following source code so that five subsequent threads print the message “Hello World number,” where number indicates the unique thread created; e.g. “Hello World 1” // Your_name_goes_here #include <pthread.h> #include <semaphore.h> sem_t semaphore; // also a global variable just like mutexes void *thread_function( void *arg ) { sem_wait( &semaphore ); // perform some task pthread_exit( NULL ); } int main() { int tmp; tmp = sem_init( &semaphore, 0, 0 ); // initialize pthread_create( &thread[i], NULL, thread_function, NULL );...
Important: please use python. Using while loop, write python code to print the times table (from...
Important: please use python. Using while loop, write python code to print the times table (from 0 to 20, incremented by 2) for number 5. Add asterisks (****) so the output looks exactly as shown below.   Please send the code and the output of the program. ****************************************************************** This Program Shows Times Table for Number 5 (from 0 to 20) Incremented by 2 * ****************************************************************** 0 x 5 = 0 2 x 5 = 10 4 x 5 = 20 6...
the language is matlab 1) Write a code that will print a list consisting of “triangle,”...
the language is matlab 1) Write a code that will print a list consisting of “triangle,” “circle,” and “square.” It prompts the user to choose one, and then prompts the user for the appropriate quantities (e.g., the radius of the circle) and then prints its area. If the user enters an invalid choice, the script simply prints an error message. For calculating the area, create separate functions for each choice. Name them as calcTriangle, calcCircle, calcSquare respectively, which are only...
Write a C++ code to print to the user a simple menu of a fast food...
Write a C++ code to print to the user a simple menu of a fast food restaurant. You should allow the user to select his/her preferred burgers and/or drinks and you should display the final bill to the user for payment. The user should be able to select more than one item. You should use the switch statement.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT