Skip to content

Commit

Permalink
Completed the waypoints tutorial and resolved the screen recording pr…
Browse files Browse the repository at this point in the history
…oblems of being played too fast (#1067)

* Allow specification of file for linear defaultstyle (#1028)

* Allow specification of file for default

* Simplify if condition

* Increase coverage (#1020)

* Add wms_control tests

* Add more mscolab tests

* Add mpl_qtwidget coverage

* Add mss_pyui coverage

* Add transparency, noframe and xml checks

* Add more wms tests

* Test import with plugins

* Add linearview tests

* Add more multilayering tests

* Revert to old testing.yml

* Leave no dangling windows

* Remove todo, move ConnectionError to bottom

Co-authored-by: ReimarBauer <[email protected]>

* Migrate existing thermodynamic functions to metpy functions (#1009)

* removed functions from thermolib.py

functions to be replaced by metpy were removed

* fixed: flake8

* fixed: flake8

* migrated to metpy functions

Co-Authored-By: J. Ungermann <[email protected]>

* Fixed: flake8

* Fixed: flake8

* Fixed tests

* Fixed: flake8

* Fixed: failing tests

* Ficed: tests

* Units discarded upon returning results

Co-Authored-By: J. Ungermann <[email protected]>

* `omega_to_w` migrated to metpy

Co-authored-by: ReimarBauer <[email protected]>
Co-authored-by: J. Ungermann <[email protected]>

* updated documentation (#1008)

* updated documentation

* improved install/update procedure

Co-authored-by: Reimar Bauer <[email protected]>

* Fixed: #999 (#1010)

* .format replaced with f" string

* updated copyright year

* fixes #1014 (#1015)

* Remove Qt imports (#1019)

* Fixes #1014 changing http to https (#1017)

Co-authored-by: ReimarBauer <[email protected]>

* Linear view mscolab bug (#1021)

* fixed tableview not opening bug; added test

* added raising of mscolab window after closing view

* preparation of v4.0.1 (#1023)

* preparation of v4.0.1

* updated install instruction

Co-authored-by: J. Ungermann <[email protected]>

* Fix pyproj 3.1.0 error (#1033)

* Made a screen recorder and automated tutorial for demonstrating use of waypoints

* Renamed tut pictures to just pictures and moved the tutorials.txt to requirements.d

* Minor bug fixes. (#1054)

* Return proper unit for eq. potential temperature (degC->K)
* Do not assume units of pressure levels for several old plotting
  styles.
* Fix values of geopotential altitude in demodata

* issue #719 solved (#729)

* issue #719 solved

* updated development.rst

* updated development.rst

Co-authored-by: ReimarBauer <[email protected]>

* Select newest init-time and carry over multilayering (#1047)

Co-authored-by: J. Ungermann <[email protected]>

* Fix some issues with elevation caching and model level dimensions. (#1061)

Fix #1066

* Added missing filename key. (#1062)

See #1066

* Waypoints tutorial completed

* Just changed the sleep timings of the code to make it more efficient : tutorial_waypoints.py

* Added the updated tutorials.txt in requirements.d

Co-authored-by: May <[email protected]>
Co-authored-by: ReimarBauer <[email protected]>
Co-authored-by: Jatin Jain <[email protected]>
Co-authored-by: J. Ungermann <[email protected]>
Co-authored-by: open-mss-build <[email protected]>
Co-authored-by: Aryan Gupta <[email protected]>
Co-authored-by: Aravind Murali <[email protected]>
Co-authored-by: J. Ungermann <[email protected]>
Co-authored-by: Archishman Sengupta <[email protected]>
  • Loading branch information
10 people authored Jul 2, 2021
1 parent fca444a commit 2eda795
Show file tree
Hide file tree
Showing 17 changed files with 408 additions and 0 deletions.
6 changes: 6 additions & 0 deletions requirements.d/tutorials.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: win-64
opencv=4.5.2=py39hcbf5309_0
pyautogui=0.9.48=py39hde42818_1
python-mss=6.1.0=pyhd3deb0d_0
Binary file added tutorials/pictures/add_waypoint.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/europe(cyl).PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/home.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/makeroundtrip.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/move_waypoint.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/next.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/options.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/pan.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/previous.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/redraw.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/remove_waypoint.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/save.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/selecttoopencontrol.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/zoom.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 140 additions & 0 deletions tutorials/screenrecorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"""
mslib.msui.screenrecorder
~~~~~~~~~~~~~~~~~~~
This python script is meant for recording the screens while automated tutorials are running.
This file is part of mss.
:copyright: Copyright 2021 Hrithik Kumar Verma
:copyright: Copyright 2021 by the mss team, see AUTHORS.
:license: APACHE-2.0, see LICENSE for details.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import numpy as np
import cv2
import datetime
import os
import sys
import time
import mss
from PyQt5 import QtWidgets


class ScreenRecorder:
"""
This is the screen recording class which helps to record the screen.
"""
def __init__(self):
"""
The constructor sets the FPS, codecs, VideoWriter object, filename, and directory
for the recording of the screen.
"""
self.record = True
self.app = QtWidgets.QApplication(sys.argv)
screen = self.app.primaryScreen()
self.width = screen.size().width()
self.height = screen.size().height()
self.fps = self.get_fps()
self.codec = cv2.VideoWriter_fourcc(*"mp4v")
current_time = datetime.datetime.now().strftime('%d-%m-%Y %H-%M-%S')
self.file_name = f'REC_{current_time}.mp4'
parent_dir = os.getcwd()
dir = "Screen Recordings"
try:
path = os.path.join(parent_dir, dir)
os.makedirs(path, exist_ok=True)
final_path = os.path.join(path, self.file_name)
except OSError:
print("Directory \"Recordings\" cannot be created")
self.recorded_video = cv2.VideoWriter(final_path, self.codec, self.fps, (self.width, self.height))
self.window_name = "Screen Recorder : MSS"
cv2.namedWindow(self.window_name, cv2.WINDOW_NORMAL)
cv2.resizeWindow(self.window_name, 480, 480)
cv2.moveWindow(self.window_name, self.width - 480, 0)

def get_fps(self):
"""
This method helps to get the Frames in one second according to the loop time and your
screen refresh rate of your monitor (if considerable in the program) and sets the FPS.
"""
with mss.mss() as sct:
bbox = {"top": 0, "left": 0, "width": self.width, "height": self.height}
fps = 0
last_time = time.time()
while time.time() - last_time < 1:
img = sct.grab(bbox)
fps += 1
img_np = np.asarray(img)
cv2.imshow("Frame Test Window", img_np)
cv2.destroyWindow("Frame Test Window")

return fps

def capture(self):
"""
Captures the frames of the screen at the rate of fps frames/second and writes into the
video writer object with the defined fourcc, codec and colour format.
"""
with mss.mss() as sct:
bbox = {"top": 0, "left": 0, "width": self.width, "height": self.height}
self.start_rec_time = time.time()
frame_time_ms = 1000 / self.fps
frames = 0
print(f"Starting to record with FPS value {self.fps} ...")
while self.record:
img = sct.grab(bbox)
img_np = np.array(img)
img_final = cv2.cvtColor(img_np, cv2.COLOR_RGBA2RGB)
cv2.imshow(self.window_name, img_final)
self.recorded_video.write(img_final)
frames += 1
expected_frames = ((time.time() - self.start_rec_time) * 1000) / frame_time_ms
surplus = frames - expected_frames

# Duplicate previous frame to meet FPS quota. Consider lowering the FPS instead!
if int(surplus) <= -1:
frames -= int(surplus)
for i in range(int(-surplus)):
self.recorded_video.write(img_final)
# Exits the screen capturing when user press 'q'
if cv2.waitKey(max(int(surplus * frame_time_ms), 1)) & 0xFF == ord('q'):
break

def stop_capture(self):
"""
When the screen is not being captured, this method is called to release the video writer
objects and destroy all windows showing additional useful information to the user.
"""
self.record = False
self.end_rec_time = time.time()
print(f".\n.\n.\n.\nFinished Recording in {self.end_rec_time - self.start_rec_time} seconds!")
self.recorded_video.release()
print(f"\n\nYour file \'{self.file_name}\' has been successfully saved in "
f"\'MSS\\tutorials\\Screen Recordings\' folder.")
cv2.destroyAllWindows()
self.app.exit()


def main():
"""
Main function calling the above functions.
"""
rec = ScreenRecorder()
rec.capture()
rec.stop_capture()


if __name__ == '__main__':
main()
Loading

0 comments on commit 2eda795

Please sign in to comment.