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 OpenCv, pandas,numpy

code be written in python,

Solutions

Expert Solution

cap=cv2.VideoCapture("vtest.avi")

ret,frame1=cap.read()
ret,frame2=cap.read()
while cap.isOpened():

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_NONE)
  
# cv2.drawContours(frame1,contours,-1,(0,0,255),4)
  
for contour in contours:
(x,y,w,h)=cv2.boundingRect(contour)
  
if cv2.contourArea(contour)<700:
continue
else:
cv2.rectangle(frame1,(x,y),(x+w,y+h),(0,255,0),3)
  
cv2.putText(frame1,"Status : Movement",(10,500),cv2.FONT_HERSHEY_SIMPLEX,2,(255,0,0),5)
  
cv2.imshow("video",frame1)
cv2.imshow("difference",diff)
cv2.imshow("difference gray",gray)
cv2.imshow("difference gray blurred",blur)
cv2.imshow("difference gray blurred thresholded",thresh)
cv2.imshow("difference gray blurred thresholded dilated",dilated)
  
frame1=frame2
ret,frame2=cap.read()
  
if cv2.waitKey(60)==27:
break
  
cv2.destroyAllWindows()
cap.release()

## The code needs cv2 , numpy as np imports .

## The code detects motion in the avi.test video and draws rectangular boxes on the the contours with area >700

#The video for this code is vtest.avi which can be found online (open cv motion detection video)


Related Solutions

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