1 of 12

GHP Day 3

Programming

2 of 12

Moving forward

I want our daily classes to look like the following:

Session 1 - Warmup, Going over homework, code-along with me in openCV or Pygame

Session 2 - Code-along with me in OpenCV and pygame

Session 3 - Time to work on pygame group project, research presentation

3 of 12

CodingBat Warmup

Let’s warmup and refresh our python by completing these problems

4 of 12

Agenda

  1. Go over homework - matrices
  2. Let’s write our first openCV program!
  3. Pygame tutorial - the basics of a pygame
  4. Pygame project
  5. Time to work on research presentation

5 of 12

OpenCV basics

  1. First, we need to create a folder where we can store all of our images we will open and all of our code.
  2. Open that folder in VS Code. Now create a new python file
  3. We’re going to learn to open an image, add two images together to blend them
  4. I want you to try to create a crazy combination of two or more images. Share your crazy images with the class!

6 of 12

Colorspaces

There are a lot of different color spaces, but the main ones we’ll use are:

  1. Gray
  2. BGR (blue - green - red)
  3. HSV (Hue - saturation - value)

7 of 12

Converting colorspaces

When you load an image using OpenCV, it is automatically set to BGR colorspace

We can convert this to any color space using the cv2.cvtColor() function

Let’s try to convert a few frames from our webcams to gray

8 of 12

Making a simple object tracker

We can use the color space data to create a simple object tracker.

Following this tutorial, we can create a simple tracker based purely on color space.

This is the simplest form of tracking, but has its limitations. What do you think these limitations are?

9 of 12

Pygame - Making a simple game

We’re going to follow this tutorial together to create a simple little game. (download data files from here and add to a data directory)

Your exercise will be to expand this game in some of the following ways:

  1. Create tighter hitboxes
  2. Use different sprites (or create your own!).
  3. Have the object you’re hitting move in different, crazy directions
  4. Use arrow keys to move your player and press a button to initiate contact with the chimp
  5. Add health and score system
  6. Create a timed challenge

10 of 12

Pygame - Create a simple game

In groups of up to 4

You are to create a simple game where your player wanders through a maze or a map.

  • They must avoid some obstacles,
  • There must be a health and scoring system
  • There must be a way out of the maze/map
  • You can incorporate some sort of combat
  • You must use your own custom art!
  • See if you can implement a menu and custom graphics
  • Design an ad or box art for your game

11 of 12

Pygame - Create a simple game

Some ways to divide the responsibilities:

  • Graphics design
  • Marketing
  • Menu design and code
  • Engine code
  • Player and enemy code
  • Obstacle code

12 of 12

Research Presentation

Your Topic Approval Form was due yesterday

The form can be located here

Important dates:

  • Tuesday, June 27 - Detailed outline due
  • Saturday, July 1 - Presentation is due