[PYTHON] How to take a captured image from a video (OpenCV)

Trigger

[How to save only a part of a long video using OpenCV] I made a script to take a capture wherever I like for a sample image of image processing from a 1-minute video acquired at (https://qiita.com/satsukiya/items/9647e20c4e27b3d0362a): laughing:

development of

Display the View and press the s [save] button on your keyboard to save the capture.

import cv2

if __name__ == '__main__':

	cap = cv2.VideoCapture('one_minutes.mp4')
	window_name = "Drop Out NHK"

	save_press_count = 1
	while True:
		presskey = cv2.waitKey(1)

		if not cap.isOpened():
			break

		ret, frame = cap.read()

		if presskey == ord('q'):
			break
		elif presskey == ord('s'):
			cv2.imwrite("capture_{}.png ".format(save_press_count), frame)
			#Save the image just by pressing the capture button
			save_press_count += 1
		cv2.imshow(window_name,frame)

	cap.release()
	cv2.destroyWindow(window_name)

result

50302312_378887672660592_5700332032704316718_n.jpg

in conclusion

I just remembered the code in OpenCV 2 Programming Book and rewrote it to C ++-> Python. I just wanted multiple images for processing.

Referenced link

-Capture opencv-cookbook camera image

Recommended Posts

How to take a captured image from a video (OpenCV)
How to create a clone from Github
How to save only a part of a long video using OpenCV
I tried to cut out a still image from the video
How to create a repository from media
Video acquisition / image shooting from a webcam
How to code a drone using image recognition
How to open a web browser from python
How to crop an image with Python + OpenCV
How to generate a Python object from JSON
How to extract coefficients from a fractional formula
100 image processing knocks !! (021-030) I want to take a break ...
How to scrape image data from flickr with python
How to loop and play gif video with openCV
[Python] How to call a c function from python (ctypes)
How to create a kubernetes pod from python code
How to call a function
How to hack a terminal
How to slice a block multiple array from a multiple array in Python
How to run a Python program from within a shell script
How to launch AWS Batch from a python client app
How to generate a public key from an SSH private key
How to get a list of links from a page from wikipedia
How to take a screenshot of the Chrome screen (prevent it from cutting off in the middle)
How to make a Japanese-English translation
How to write a Python class
How to use SWIG from waf
How to put a symbolic link
How to make a slack bot
How to create a Conda package
Try to extract a character string from an image with Python3
How to get a string from a command line argument in python
How to make a crawler --Advanced
[Python] How to get & change rows / columns / values from a table.
How to make a recursive function
How to create a virtual bridge
How to make a .dylib library from a .a library on OSX (El Capitan)
How to extract the desired character string from a line 4 commands
How to launch Explorer from WSL
How to make a deadman's switch
How to create a Dockerfile (basic)
[Blender] How to make a Blender plugin
Convert a string to an image
How to delete a Docker container
How to access wikipedia from python
How to get a job as an engineer from your 30s
How to make a crawler --Basic
How to convert from .mgz to .nii.gz
How to remove duplicates from a Python list while preserving order.
Introduction to image analysis opencv python
How to create a config file
How to make a face image data set used in machine learning (3: Face image generation from candidate images Part 1)
[EC2] How to take a screen capture of your smartphone with selenium
How to crop the lower right part of the image with Python OpenCV
How to send a visualization image of data created in Python to Typetalk
How to get a value from a parameter store in lambda (using python)
How to get a namespaced view name from a URL (path_info) in Django
How to get a sample report from a hash value using VirusTotal's API
How to play a video while watching the number of frames (Mac)
[python] Send the image captured from the webcam to the server and save it
How to split and save a DataFrame