Project description

In this project you will use a camera to detect the theft of a valuable red ruby called the red panther.

Red ruby

The skills you develop in this mini-project, and perhaps some of the actual code, can be used in the AVC project (Project 3). Your job is to develop code that detects whether the ruby has been stolen in a series of images provided. There are two key behaviours that are required (see details under marking):
  • Your system should detect whether the ruby is present on start-up.
  • Your system should not give false alarms when the room lights are brightened or dimmed, or when a shadow is cast, for example when someone walks past the system blocking part of the light.
  • Your system should detect a theft, for example when one of the tutors removes the ruby perhaps while sliding another, fake ruby into the field of view to confuse your system (challenge).

Working with the hardware

We will be using a minicomputer called a Raspberry PI (RPI) for this project.

Powering up procedure:
  • Make sure that the display is connected to the RPI. Switch the display to the DVI input (use thge second button from the bottom on the right of the display to get to the menu).
  • To start the RPI plug the power supply cable (miniUSB) into a USB port of the PC.
  • The display briefly shows a set of colours. If not - check the display connection and make sure that the SD card (which contains the RPI OS ) is fully inserted.
  • When the RPI starts, the Graphical User Interface (GUI) is not enabled by default, and only a command line is displayed. The RPI is not a powerful computer and using a GUI slows it down significantly. For this Project using a GUI is reasonable. To launch the GUI type startx, push "Enter" and wait several seconds.

Red ruby

When you finish a significant amount of work we recommend that you transfer your file from the RPI to the ECS folder as a backup. You can use software called Filezilla. Enter the server name, your ECS user name and password, port 22. Delete your code from the RPI at the end of the session if you are SURE it has been saved.

Software description

To start

Start the File Explorer and navigate to the Project 2 folder. Find the file starting.cpp which you can use as a starting point for this Project.

Start Geany and load this file. Don't modify it (the next student using same RPI will need it), rather make new folder for your code and save a your cpp file into it. The procedure for compiling it is below.

There is a library installed on all the RPIs which provides low-level hardware control functions. The header file for this library is shown in the listing below. For this Project we will use only video functions. Here is the list of functions.

void stoph(); //stops all hardware, including camera
int init(int debug_level); // should be called before 
// any library functions. Set "debug_level" to 0 if you don't want debug E101 library information
int take_picture();    // loads pixels from camera into memory
int save_picture(char fn[5]);
char get_pixel( int row,int col, int color); // returns color value of one pixel
// color=0 - returns red; color=1 - returns green; color=2 - returns blue;
// color=3 - returns (red + green + blue)/3 
int set_pixel(int row, int col, char red, char green,char blue);
// you can modify the image
void convert_camera_to_screen(); // call before displaying the image
int open_screen_stream();
int close_screen_stream();
int update_screen();     // shows picture in memory on the screen

When compiling your program make sure that E101.h is in the same folder as your program. Add -le101 to the Build command of Geany using Set Build Commands menu options.

The standard graphical coordinate system is used: top-left point is (0,0), row number increases going down, column number increases going to the right.
get pixel.png
Image coordinate system

Your software

Let us start with Core.

The code for the Core (starting.cpp) is a rather crude measure of whether the ruby is present. It works poorly and Howard will be able to steal your ruby if you do not make improvements.

Your Core code should print a message on the screen telling the user the ruby is still there, or that it was stolen, or that a burglary is underway right now.


Project 2 accounts for 13% of the entire course as specified below. Marking is done by testing your code in the lab. Note one code needs to cover all of the requirements. You cannot make separate code for each requirement.

CODE (All the Project 2 code together accounts for 8% of ENGR 101 course grade, broken down as follows):

CORE CODE (65% of code mark)

Your code must compile and run, and the system must reliably detect whether the ruby is present in room lights when your system starts up. The system must post a message stating whether the ruby is present at start up and must continuously display a video image of the ruby. Note that the lighting in the room varies from spot to spot and day to day, and the provided code will not work well.


False Alarms (8% of code mark)

The system must not give a false alarm in these tests:
  • An A4 sheet will be used to cover the apparatus by placing it on top of the stand to create a shadow.
  • The set of room lights nearest your station will be turned off but the other lights will be left on.
  • A person will walk past the Red Panther, casting a shadow.

Theft (7% of code mark)

  • The ruby will be removed. The system must display a message noting the theft within two

CHALLENGE CODE (20% of code mark)

Howard or a tutor will try to replace the ruby with a fake one under varying lighting conditions using varying techniques. If we fail to take the ruby without setting off your alarm in three attempts, you win full challenge marks.

Code Submission

Submit your .cpp file.

REFLECTION (5% of the course grade)

The reflection should explain the strategies you used to detect the presence and theft of the Red Panther, and how you implemented these strategies in code. The reflection should also discuss how well your system worked and suggest improvements.\ Submit one .pdf file with the reflection.
I Attachment Action Size Date Who Comment
Images.zipzip manage 3 MB 05 Feb 2022 - 10:08 Main.arthur  
display.htmlhtml display.html manage 429 bytes 05 Feb 2022 - 10:11 Main.arthur  
get_pixel.pngpng get_pixel.png manage 22 K 30 Mar 2023 - 12:58 Main.arthur  
rpi.pngpng rpi.png manage 721 K 30 Mar 2023 - 12:26 Main.arthur  
rr10.pngpng rr10.png manage 41 K 30 Mar 2023 - 11:51 Main.arthur  
video_proc.hpphpp video_proc.hpp manage 4 K 22 Mar 2022 - 10:59 Main.arthur