Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extraction of Images from Videos and Leaderboard update MWoC #746

Merged
merged 3 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'Label Actions'
on:
pull_request:
types: labeled

jobs:
add-score:
runs-on: ubuntu-latest
if: startsWith(github.event.label.name, 'user')
steps:
- run: |
echo ${{ github.event.label.name }}
SCORE=${{ github.event.label.name }}
echo $SCORE
curl --data "score=$SCORE" --request POST https://wocleaderboard-backend.herokuapp.com/updateLeaderBoard/
35 changes: 18 additions & 17 deletions Python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,21 @@ S. No | Name of Script | Directory Link | Author | Tools Used |
144 | Valid Phone Number Extractor | [Click Here](/Python/Valid_Phone_Number_Extractor) | [Hitesh Kumar](https://github.com/HeroicHitesh) | re, argparse
145 | Video Steganography | [Click Here](/Python/Video_Steganography) | [Vedansh Vijaywargiya](https://github.com/vvHacker007) | numpy, cv2, math, subprocess
146 | Video To Frames | [Click Here](/Python/Video_To_Frames) | [Kaustubh](https://github.com/kaustubhgupta) | cv2, sys
147 | Video Watermarker | [Click Here](/Python/Video_Watermarker) | [Kaustubh Gupta](https://github.com/kaustubhgupta) | cv2, tqdm, moviepy.ediotr
148 | Vigenere Cipher | [Click Here](/Python/Vigenere_Cipher) | [Mohit Gupta](https://github.com/mohitacecode) | -
149 | Watermark It | [Click Here](/Python/Watermark_it) | [Aditya Jetely](https://github.com/AdityaJ7) | pdfrw, sys, os
150 | Website Blocker | [Click Here](/Python/Website_Blocker) | [Ankita Priya](https://github.com/AnkitaBIT) | datetime
151 | Website Cloner | [Click Here](/Python/Website_Cloner) | [Avinash Kr. Ranjan](https://github.com/avinashkranjan) | logging, cssutils, BeautifulSoup
152 | Weather Using Open Weather Map | [Click Here](/Python/Weather_using_OpenWeatherMap) | [Namya LG](https://github.com/Namyalg) | requests, json, sys
153 | WhatsApp Message Automation | [Click Here](/Python/WhatsApp_Message_Automation) | [Namya LG](https://github.com/Namyalg) | selenium, time
154 | WhatsApp SMS Bomber | [Click Here](/Python/Whatsapp_Sms_Bomber) | [ANSHUMALI SHAW](https://github.com/bagofcodes) | selenium, tkinter, xpath
155 | Who is Online On WhatsApp | [Click Here](/Python/Who_Is_Online_On_WhatsApp) | [Wable Sanket](https://github.com/Sanketwable) | selenium, time, users
156 | Word Meaning | [Click Here](/Python/Word_Meaning) | [Mohit Gupta](https://github.com/mohitacecode) | PyDictionary
157 | Wifi Spped Tester | [Click Here](/Python/Wifi%20Speed%20Tester) | [Vedansh Vijaywargiya](https://github.com/vvHacker007) | win10toast, speedtest
158 | XML To CSV | [Click Here](/Python/XML_To_CSV) | [Harsh Bardhan Mishra](https://github.com/HarshCasper) | glob, pandas
159 | Youtube Bot | [Click Here](/Python/Youtube_Bot) | [Sri Manikanta Palakollu](https://github.com/srimani-programmer) | time, argparse, selenium
160 | Youtube Video Download | [Click Here](/Python/Youtube_Video_Download) | [Anushka-S10](https://github.com/Anushka-S10) | pytube
161 | YouTube Video-Audio Download | [Click Here](/Python/YouTube_Video-Audio_Download) | [Naman Shah](https://github.com/namanshah01) | os, sys, pafy, requests
162 | Zipper | [Click Here](/Python/Zipper) | [Puneet Pal Singh](https://github.com/Puneet-Pal-Singh) | os, zipfile, datetime
163 | Zoom Automation | [Click Here](/Python/Zoom_Automation) | [Rutuja Dhanawade](https://github.com/rutujadhanawade) | pyautogui, time
147 | Video to Images(req. FPS/Frate) | [Click Here](/Python/vid_2_img_fps) | [Rutvik J](https://github.com/RutvikJ77) | cv2, sys, args
148 | Video Watermarker | [Click Here](/Python/Video_Watermarker) | [Kaustubh Gupta](https://github.com/kaustubhgupta) | cv2, tqdm, moviepy.ediotr
149 | Vigenere Cipher | [Click Here](/Python/Vigenere_Cipher) | [Mohit Gupta](https://github.com/mohitacecode) | -
150 | Watermark It | [Click Here](/Python/Watermark_it) | [Aditya Jetely](https://github.com/AdityaJ7) | pdfrw, sys, os
151 | Website Blocker | [Click Here](/Python/Website_Blocker) | [Ankita Priya](https://github.com/AnkitaBIT) | datetime
152 | Website Cloner | [Click Here](/Python/Website_Cloner) | [Avinash Kr. Ranjan](https://github.com/avinashkranjan) | logging, cssutils, BeautifulSoup
153 | Weather Using Open Weather Map | [Click Here](/Python/Weather_using_OpenWeatherMap) | [Namya LG](https://github.com/Namyalg) | requests, json, sys
154 | WhatsApp Message Automation | [Click Here](/Python/WhatsApp_Message_Automation) | [Namya LG](https://github.com/Namyalg) | selenium, time
155 | WhatsApp SMS Bomber | [Click Here](/Python/Whatsapp_Sms_Bomber) | [ANSHUMALI SHAW](https://github.com/bagofcodes) | selenium, tkinter, xpath
156 | Who is Online On WhatsApp | [Click Here](/Python/Who_Is_Online_On_WhatsApp) | [Wable Sanket](https://github.com/Sanketwable) | selenium, time, users
157 | Word Meaning | [Click Here](/Python/Word_Meaning) | [Mohit Gupta](https://github.com/mohitacecode) | PyDictionary
158 | Wifi Spped Tester | [Click Here](/Python/Wifi%20Speed%20Tester) | [Vedansh Vijaywargiya](https://github.com/vvHacker007) | win10toast, speedtest
159 | XML To CSV | [Click Here](/Python/XML_To_CSV) | [Harsh Bardhan Mishra](https://github.com/HarshCasper) | glob, pandas
160 | Youtube Bot | [Click Here](/Python/Youtube_Bot) | [Sri Manikanta Palakollu](https://github.com/srimani-programmer) | time, argparse, selenium
161 | Youtube Video Download | [Click Here](/Python/Youtube_Video_Download) | [Anushka-S10](https://github.com/Anushka-S10) | pytube
162 | YouTube Video-Audio Download | [Click Here](/Python/YouTube_Video-Audio_Download) | [Naman Shah](https://github.com/namanshah01) | os, sys, pafy, requests
163 | Zipper | [Click Here](/Python/Zipper) | [Puneet Pal Singh](https://github.com/Puneet-Pal-Singh) | os, zipfile, datetime
164 | Zoom Automation | [Click Here](/Python/Zoom_Automation) | [Rutuja Dhanawade](https://github.com/rutujadhanawade) | pyautogui, time
33 changes: 33 additions & 0 deletions Python/vid_2_img_fps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Video to Image at required FPS
This python script converts video to images at a required framerate which can be useful for Extracting Deep Learning training images.
There are two files single_convert uses a single video and multi_convert requires the video files specified as an input.

# How to use?
Just type in:

`python single_convert.py --input videofile.mp4 --output output_dir --frate 1`

This will convert the video file into images at 1s per framerate meaning it will extract images every one second.

`python multi_convert.py --input videofile.mp4 --output output_dir --frate 1`

This will convert the video files into images at 1s per framerate meaning it will extract images every one second.

You can always type in:

`python single_convert.py -h` or `python single_convert.py -h` for any help with arguments.


```
-i --input (input argument)
-o --output (output path)
-fps --framesps (Requried frame rate)
-frate --frate (Required frames per second) default set to 0.1
```

# Requirements
Before running the script, just install open-cv for python using this command:

`pip install opencv-python`

> Happy Extracting images.
56 changes: 56 additions & 0 deletions Python/vid_2_img_fps/multi_convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import argparse
import cv2

#Necessary Arguments
ap = argparse.ArgumentParser()
ap.add_argument('-i', "--input", required=True, type=str, help="Input for the video files",)
ap.add_argument('-o', "--output", type=str, help="Output directory for the images extracted")
ap.add_argument('-fps', "--framesps", default=int(cv2.CAP_PROP_FPS), help="Extract at the desired Frame rate")
ap.add_argument('-frate', "--frate", default=0.1, type=float, help="To determine the amount of frames to be extracted per second")
args = vars(ap.parse_args())

video_path = args['input']
save_path = args['output']
skip_frames = args['framesps']
frameRate = args['frate']

def length_of_video(video_p):
cap = cv2.VideoCapture(video_p)
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
return length

def extracting_frames(video_pa, op_path, skip_frame, filen):
length = length_of_video(video_pa)
if length == 0:
print("Length is 0,Video not Available")
return 0

cap = cv2.VideoCapture(video_pa)
count = 0

ret, frame = cap.read()
test_file_path = op_path + "image" + str(count) +".png"
cv2.imwrite(test_file_path, frame)

if os.path.isfile(test_file_path):
print("Saving Test Frame successful")
count = 1
while ret:
ret, frame = cap.read()
if ret and count % int(skip_frame/(frameRate)) == 0:
#Naming
name = op_path + filen.split('.')[0] + '-' + "frame" + str(count) +".png"
cv2.imwrite(name, frame)
count += 1
else:
count += 1
else:
print("Problem saving the Test Frame.")
return 0
print(filen +' completed')
cap.release()

for filename in os.listdir(video_path):
f_path = video_path + filename
extracting_frames(f_path, save_path, skip_frames, filename)
60 changes: 60 additions & 0 deletions Python/vid_2_img_fps/single_convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import argparse
import os
import cv2

# Necessary Arguments
ap = argparse.ArgumentParser()
ap.add_argument('-i', "--input", required=True, type=str, help="Input for the video files")
ap.add_argument('-o', "--output", required=True, type=str, help="Output directory for the images extracted")
ap.add_argument('-fps', "--framesps", default=int(cv2.CAP_PROP_FPS), help="Extract at the desired Frame rate")
ap.add_argument('-frate', "--frate", default=0.1, type=float, help="To determine the amount of frames to be extracted per second")
args = vars(ap.parse_args())

video_path = args['input']
save_path = args['output']
skip_frames = args['framesps']
frameRate = args['frate']

def length_of_video(video_p):
'''
Gets the input length of video and returns it.
'''
cap = cv2.VideoCapture(video_p)
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
return length

def extracting_frames(video_pa, op_path, skip_frame):
'''
Extracting function for the images
'''
length = length_of_video(video_pa)
if length == 0:
print("Length is 0,Video not Available")
return 0

cap = cv2.VideoCapture(video_pa)
count = 0

ret, frame = cap.read()
test_file_path = op_path + "image" + str(count) +".png"
cv2.imwrite(test_file_path, frame)

if os.path.isfile(test_file_path):
print("Saving Test Frame successful")
count = 1
while ret:
ret, frame = cap.read()
if ret and count % int(skip_frame/(frameRate)) == 0:
#naming
name = op_path + "image" + str(count) +".png"
cv2.imwrite(name, frame)
print(name)
count += 1
else:
count += 1
else:
print("Problem saving the Test Frame.")
return 0
cap.release()

extracting_frames(video_path, save_path, skip_frames)