Questions & AnswersPython Programming

What you will need to do is: Calculate the absolute difference...

Question
Answered step-by-step
Asked by KidSeahorse4319 on coursehero.com

What you will need to do is: Calculate the absolute difference...

What you will need to do is:

Calculate the absolute difference frame between two frames as the camera is capturing frames

and threshold them with a specific value e.g. 20. Save the output abs. diff. frame in a video file.

Try for example to move your hands in front of the camera while capturing and analyzing the

frames. You should be able to visually identify well the contour of your hands when these are

moving but not so much when they are staying still.

 

This part continues from our previous demo with capturing frames from the camera using

load_camera.py

 

The load_camera.py:

 

# Load opencv module

import cv2



 

# Creat a VideoCapture object

cap = cv2.VideoCapture(0)


 

# Check if camera opened successfully

if (cap.isOpened() is False):

print("Unable to read camera feed")


 

# Default resolutions of the frame are obtained.

# The default resolutions

# are system dependent.

# We convert the resolutions from float to integer.

frame_width = int(cap.get(3))

frame_height = int(cap.get(4))


 

# Define the codec and create VideoWriter object. The output is

# stored in 'output.avi' file.

out = cv2.VideoWriter('output.avi',

cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'),

10, (frame_width,frame_height))


 

while(True):

ret, frame = cap.read()


 

if ret:


 

# color to grayscale

# Write the frame into the file 'output.avi'

out.write(frame)

print(frame.dtype)

print(frame.shape)


 

# Display the resulting frame

cv2.imshow('frame', frame)


 

# Press Q on keyboard to stop recording

if cv2.waitKey(1) & 0xFF == ord('q'):

break


 

# Break the loop

else:

break


 

# When everything done,

# release the video capture and write objects

cap.release()

out.release()


 

# Closes all the frames

cv2.destroyAllWindows()

Answer & Explanation

Solved by verified expert
Answered by MasterBook10144 on coursehero.com
<p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis.</p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem
CliffsNotes Logo

Unlock access to this and over
10,000 step-by-step explanations

Unlock Explanation

Have an account? Log In

Step-by-step explanation

<p style="margin-left:0px;">sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing e</p><p style="margin-left:0px;"> </p><p style="margin-left:0px;">sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet.</p><p style="margin-left:0px;"> </p><p style="margin-left:0px;">sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam r</p><p style="margin-left:0px;"><img src="/qa/attachment/39128045/" alt="39128045"/><img src="/qa/attachment/39128044/" alt="39128044"/><br/><img src="/qa/attachment/39128050/" alt="39128050"/></p><p style="margin-left:0px;"> </p>
3 attachments
Subscribe to unlock attachment
JPEG
Subscribe to unlock attachment
JPEG
Subscribe to unlock attachment
JPEG

Get unstuck with a CliffsNotes subscription

Example CliffsNotes Question and Answer
Unlock every step-by-step explanation, download literature note PDFs, plus more.Get Access

Related Q&A