Last active
June 24, 2019 02:05
-
-
Save d-j-kendall/2b6a253142629fed119cf5b429ce2a7d to your computer and use it in GitHub Desktop.
getting images from videos using python and opencv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"4.1.0\n" | |
] | |
} | |
], | |
"source": [ | |
"import cv2\n", | |
"print(cv2.__version__)\n", | |
"vidcap = cv2.VideoCapture('../../data/european-roulette-220.mp4')\n", | |
"success,image = vidcap.read()\n", | |
"count = 0\n", | |
"success = True\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"while success:\n", | |
" vidcap.set(1,count)\n", | |
" success,image = vidcap.read() \n", | |
" cv2.imwrite(\"images/frame%d.jpg\" % count, image) # save frame as JPEG file\n", | |
" count += 1000" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"190888\n" | |
] | |
} | |
], | |
"source": [ | |
"frame_count = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))\n", | |
"print(frame_count)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment