Python may already be installed.
For Windows, Python can be downloaded from here
https://www.python.org/downloads/windows/. Typically the best one is Python 3 in Stable Releases
and is 64-bit.
For Ubuntu, Python 3 is typically already installed.
Ubuntu requires the "python3" command to run the software.
If you don't have it, it can be installed from
www.python.org.
The first demonstration programs do not require installing packages.
Using Jupyter does not require installing packages.
Install pip using instructions here
https://pip.pypa.io/en/stable/installing/
For Ubuntu, open a terminal and run:
$ pip3 install python3-pygame
Or
$ sudo apt-get install python3-pygame
Or follow the instructions here:
www.pygame.org/wiki/GettingStarted
This is only required for programs in the image-proc folder.
For Ubuntu, open a terminal and run:
$ pip3 install python3-opencv
Or
$ sudo apt-get install python3-opencv
Or follow the instructions here:
https://docs.opencv.org/master/d2/de6/tutorial_py_setup_in_ubuntu.html
Or here:
https://docs.opencv.org/master/d5/de5/tutorial_py_setup_in_windows.html
For Ubuntu:
- Click on the "Files" icon (File Folder Viewer) on the left side of the screen.
Or run Activities and enter "Nautilus".
- Click on folders in the "explorer"
- Once the correct folder is selected, then right click with the mouse and
select, "Open in Terminal"
- Then the prompt is displayed. If there are instructions such as, "$ ls *",
the "$" part should not be entered since it is indicating the prompt that
is displayed.
There are many ways to run the Python demo programs.
Python program can be run from the Idle program.
Python programs can be run from a terminal.
First open a terminal, and then
enter the text required to run the program. In the Demos
documentation, the text to run is shown.
Another way is to right click on the file that you would like to edit and run,
then select "Open With Other Application", then select "Idle". Then select "Run/Run Module" or the key F5.
The demo programs can also be run from Jupyter.
Editing Python programs can be done with any text editor. The default
Python editor is "Idle" and has colored text so that it is easier to
read.
For Ubuntu:
- Right click on a .py file.
- Select "Open with Other Application"
- Select "Idle"
The menu Run/Run Module will run the program. The Python Shell may not show anything,
but most demos will show a new window somewhere on the screen.
Often searching on the internet will help to find out how
to solve a problem. Other types of problems require
debugging.
It is possible to debug Python programs by inserting statements
into the program. Some examples are:
Statement | Description |
print('1') | This will print a "1" to the terminal when the print
statement is run. |
print(object) | This will print the content values of an object or variable |
print(dir(object)) | This will print the methods or members of an object or variable |
print(type(object)) | This will print the type of an object or variable |
print('place1', str(obj)) | This will print 'place1' and information about an object. |
There are some Python editors that allow debugging. Search the internet
for "Python IDE" to find different editors.
An image can be saved of the current screen or window.
For Ubuntu:
- Click on the "Activities" menu.
- Enter "Screenshot" in the "Type to Search" box.
- Click "Take Screenshot"
A movie can be saved of the activities during some animation, or selections on the screen.
For Ubuntu:
- Click on the "Activities" menu.
- Enter "Screenshot" in the "Type to Search" box.
- Enter a delay of a few seconds.
- Press Ctrl-Alt-Shift-R to start recording.
- Run your program.
- Press Ctrl-Alt-Shift-R to stop recording.
- The output file is saved in home directory in the "Videos" folder.
Install "WinFF" using Synaptic or command line.
A video can also be edited in Gimp to change individual frames.
Cut and Crop
- Run WinFF
- Click the Options. This will show extra tabs in the screen.
- Use the Crop tab to indicate how many pixels to remove from each side.
- Use the Time tab to select when to start keeping the video and how much to keep.
- Use Preview to view the changes.
- Use Convert to save the file in the home directory.
It seems like both Crop and changing the video size don't work at the same time.
So load the already cropped video, and use the Video tab to set the output size.
Set Image Size
A complete example for the game/bug-data/Bug-Source/Bug.mp4 is:
- Video: Frame Rate=5, Video Size=100 X -1
- Time: Seek to=5, Time to Record=6
Extract Frames
To extract frames, first open a terminal, and then run:
/usr/bin/ffmpeg -i "/dir/game/bug-data/Bug.mp4" /dir/game/bug-data/Bug/frame_%03d.png
The dir in italics must be replaced with your actual folder.