EET207 Week 4 – Assignment (Alternate) Introduction: This lab is in lieu of Week 4 Lab 2 in the event you do not have access to the Raspberry Pi and/or the Pi web camera. This lab will use Python on a...

1 answer below »






EET207







Week 4 – Assignment
(Alternate)







Introduction:






This lab is in lieu of Week 4 Lab 2
in the event you do not have access to the Raspberry Pi and/or the Pi web
camera. This lab will use Python on a PC with an attached web camera.






You will install opencv-python from
a terminal prompt and then import cv2 in your Python script.






# You will learn how to connect to
the camera using the web and remotely control the PI camera.






# You will practice how to activate
motion detection such the camera turns on automatically if a motion is
detected.






#You will practice taking a picture
using the web camera.







Lab Materials:











The
following components will be needed to complete this LAB:








1.


PC
with Python and PyCharm installed








2.


A
web camera







Instructions:







Step 1:
Install
opencv-python using pip at the terminal











Text Box: pip install opencv-python







Step 2:
Ensure your PC’s
webcam is enabled.







Step 3:
Display live video
by running the following script







Text Box: # Lab 4-2 alternate View webcam<br>import cv2<br>cap = cv2.VideoCapture(0)<br>while True:<br>    ret, frame = cap.read()<br>    cv2.imshow('frame', frame)<br>    if cv2.waitKey(1) & 0xFF == ord('q'):<br>        break<br><br>













































Step 4:
Comment on the
results of step 3 in your submission document.







Step 5:
Take a series of photos
using the following script







Text Box: # 1.creating a video object<br>import cv2<br>video = cv2.VideoCapture(0)<br># 2. Set up a counter variable<br>a = 0<br>print(




















































Step 6:
Insert at least 3
of the images captured in the previous step. The images should be in the folder
containing your Python project.







Step 7:
Take a screen
capture of the file names captured.







Step 8:
Comment on the
operation of the above program







Step 9:
Write a python
program, based on the program in step 5,


that will take (and save) 3, 4, or 5 photos at 1 second intervals
depending on whether the ‘3’, ‘4’, or ‘5’ key was pressed and then terminate.
No action should occur if any other key is pressed. The photos should be
consecutively numbered. Use loops wherever practical.







Hint:
Consider importing
the time module.







Step 10. Use the following
python script
to detect motion and test
it.







#
Python program to implement








#
Webcam Motion Detector
















#
importing OpenCV, time and Pandas library









import



cv2, time, pandas







#
importing datetime class from datetime library









from



datetime


import



datetime















#
Assigning our static_back to None








static_back


=



None















#
List when any moving object appear








motion_list


=



[

None
,

None


]















#
Time of movement








time


=



[]















#
Initializing DataFrame, one column is start








#
time and other column is end time








df


=



pandas.DataFrame(columns


=



[
"Start"
,

"End"
])















#
Capturing video








video


=



cv2.VideoCapture(
0
)















#
Infinite while loop to treat stack of image as video









while



True
:








#
Reading frame(image) from video









check, frame


=



video.read()
















# Initializing
motion = 0(no motion)









motion


=



0
















#
Converting color image to gray_scale image









gray


=



cv2.cvtColor(frame,
cv2.COLOR_BGR2GRAY)

















#
Converting gray scale image to GaussianBlur









#
so that change can be find easily









gray


=



cv2.GaussianBlur(gray, (
21
,

21
),

0
)
















#
In first iteration we assign the value









#
of static_back to our first frame










if



static_back


is



None
:








static_back


=



gray









continue

















#
Difference between static background









#
and current frame(which is GaussianBlur)









diff_frame


=



cv2.absdiff(static_back, gray)
















#
If change in between static background and









#
current frame is greater than 30 it will show white color(255)









thresh_frame


=



cv2.threshold(diff_frame,

30
,

255
, cv2.THRESH_BINARY)[
1
]








thresh_frame


=



cv2.dilate(thresh_frame,

None
, iterations


=



2
)
















#
Finding contour of moving object









cnts,_


=



cv2.findContours(thresh_frame.copy(),








cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)


















for



contour


in



cnts:









if



cv2.contourArea(contour)

10000
:









continue









motion


=



1
















(x, y, w, h)


=



cv2.boundingRect(contour)








#
making green rectangle around the moving object









cv2.rectangle(frame, (x, y), (x



+



w, y


+



h), (
0
,

255
,

0
),

3
)
















#
Appending status of motion









motion_list.append(motion)
















motion_list


=



motion_list[

-

2
:]
















#
Appending Start time of motion










if



motion_list[

-

1
]


==



1



and



motion_list[

-

2
]


==



0
:








time.append(datetime.now())
















#
Appending End time of motion










if



motion_list[

-

1
]


==



0



and



motion_list[

-

2
]


==



1
:








time.append(datetime.now())
















#
Displaying image in gray_scale









cv2.imshow(
"Gray Frame"
, gray)
















#
Displaying the difference in currentframe to









#
the staticframe(very first_frame)









cv2.imshow(
"Difference Frame"
, diff_frame)
















#
Displaying the black and white image in which if









#
intensity difference greater than 30 it will appear white









cv2.imshow(
"Threshold Frame"
, thresh_frame)
















#
Displaying color frame with contour of motion of object









cv2.imshow(
"Color Frame"
, frame)
















key


=



cv2.waitKey(
1
)








#
if q entered whole process will stop










if



key


==



ord
(
'q'
):








#
if something is movingthen it append the end time of movement










if



motion


==



1
:








time.append(datetime.now())









break
















#
Appending time of motion in DataFrame









for



i


in



range
(
0
,

len
(time),

2
):








df


=



df.append({
"Start"
:time[i],

"End"
:time[i


+



1
]}, ignore_index


=



True
)















#
Creating a CSV file in which time of movements will be saved








df.to_csv(
"Time_of_movements.csv"
)















video.release()















#
Destroying all the windows








cv2.destroyAllWindows()












Step 11. After testing the
script in step 10, provide an analysis of the script. Report any bugs found and
what you would do to correct them.







Step 12.
Submit the
document with required comments and photos along with the python script for
step 9.






Answered 2 days AfterSep 19, 2022

Answer To: EET207 Week 4 – Assignment (Alternate) Introduction: This lab is in lieu of Week 4 Lab 2 in the...

Sathishkumar answered on Sep 21 2022
70 Votes
Lab Report (EET207)
Abstract:
Motion detection has become one of the most essential aspects in the field of home security since it can be used to improve a wide variety of devices, from motion sensor lights to interior and outdoor security cameras. Because of this, motion detection has risen to become a crucial component. Businesses, houses, public venues, and private areas may all benefit from incre
ased security provided by motion sensors. Devices for detection must be developed with the incorporation of AI. Given this, we have begun developing a work on a motion detector to enhance an existing home security system. The open CV will be used in this endeavour in order to reach our goals and succeed. Eliminating the surrounding context in order to focus on the front element of a scene and standing out as one of the first to do anything. Now that we have a setting, we can begin to pull out the individual frames. Because of this, every time motion is detected, a scene from black history may be shown.
1. Introduction
Motion detection is an important component of many different types of machine vision-based systems. For instance, when we want to count the number of people who have gathered at a location such as a stadium or a park, or when we want to count how many units of a certain product are being produced by a machine at a factory, we may use counters. In each of these scenarios, we need to remove the individuals and any other items that are present at the scene. Motion detection may be accomplished by the use of a variety of approaches, procedures, or algorithms. To do this, we will be using Open-Source CV.
Motion detection technology is found in a variety of devices, one of the most prevalent of which is a security camera. The need for a modernised and technologically sophisticated security system is developing at a fast rate, and as a result, people in today's world seek apps that are based on artificial intelligence to build environments that are free from theft.
A trade-off must be made between the attacker and the defence in order to achieve security. Sadly, such equilibrium is never maintained in a single state. Alterations in technology have an impact in both directions. The scope of defection, or what an attacker can use to get away with, is something that can be reduced by societies with the use of new technology, while attackers can enhance it with the help of new technologies.
Motion detector cameras and other instruments are an absolute need in today's world in order to improve the safety of our homes, public spaces, private spaces, and places of employment.
The detection of motion via the use of artificial intelligence is the goal of this project. The advantage is that motion will be noticed in an effective manner, and it will be of assistance to the other security systems that we already have.
In order to complete this project, we will be using the following technologies:
1.1 OPEN CV:
Open-Source Computer Vision is a machine learning software library that gives users access to computer vision tools and libraries that are geared for real-time use. OpenCV was developed to offer a standard infrastructure for computer vision applications and to speed the usage of machine perception in commercial goods. Its primary goal was to accomplish these objectives. OpenCV is a product that is licenced under the BSD, which makes it simple for companies to employ and customise the code. Image processing, motion detection, face recognition, and other functions may all be accomplished using Python with the help of this module.
1.2 PYTHON
Python is a general-purpose programming language that operates at a high level. Because it is object oriented, it makes it easier for programmers to develop code that is both explicit and logical when solving a problem. Open CV provides support for the Python programming language, which may be used to analyse photos and videos to recognise faces, detect motion, and identify objects.
2. Implementation
The step-by-step implementation and...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here