Calculate the absolute difference frame between two frames as the camera is capturing frames and threshold them with a specific
This problem has been solved!
Do you need an answer to a question different from the above? Ask your question!
Question:
- 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()
Related Book For
Managerial Accounting Creating Value in a Dynamic Business Environment
ISBN: 978-0078110917
9th edition
Authors: Ronald W. Hilton
View Solution
Create a free account to access the answer
Cannot find your solution?
Post a FREE question now and get an answer within minutes.
* Average response time.
Posted Date: September 02, 2023 02:01:44