2017/11/22 COMP2011 Assignment 3: Video Monitoring
OBJECTIVE
The objective of this assignment is to provide opportunities for students to better familiar with memory management (allocation and deallocation) and
the manipulation of linked list. Besides the involved different structures also provide students an opportunity to know how different components should
interact with each other in a project.
INTRODUCTION
In this project, you are required to implement a simple software for traffic monitoring. More specifically, given a 'video' captured above a road, you are
required to analyze the traffic situations like the speed and position of each vehicle in each video frame. The input 'video' is a text file that stores each
frame. with the resolution of 9x30 (ROWSxCOLS). You can download an example video here, and note that no real videos will be used in this project.
GETTING START
We have provided a skeleton code for you to work on. Students must download the skeleton code and complete the missing part in the file pa3.cpp. To
start the project, you will need to create a new project on Eclipse and copy the skeleton code files to the project directory. Refresh the directory
afterwards. The main.cpp and structure.h are complete and you are not allowed to modify them. However, you are expected to read these two files to
understand the assignment.
INPUT VIDEO
The video is a text file that stores the number of frames and each frame's data. Each frame. (9 rows, 30 column) presents a oneway street with four
lanes with width of 1 row. In each frame, the fence between two lanes is represented by the character '', and the ground is '>' and vehicle is '*'. An
example frame. data with two vehicles is shown below. In this frame, the first vehicle is in the first lane while the second vehicle is in the third lane.
------------------------------
>>>>>*>>>>>>>>>>>>>>>>>>>>>>>>
------------------------------
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
------------------------------
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
------------------------------
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
------------------------------
In this assignment the image coordinate (row, column) is used to describe the position of each pixel, and rows are counted from zero from top to
bottom, while columns are counted from zero from left to right. For example, the first vehicle in the above frame. is in position (1, 5). Also, to simplify
the monitoring task, in this assignment we assume that:
Each given video will have successive frames indexed from zero. The frame. index will not jump (e.g., frame. 3 must be followed by frame. 4 or
eof).
Each vehicle will drive from left to right within its lane.
The distance between two different vehicles on the same lane must be greater than 8 (MAX_SPEED).
The distance between one vehicle in two successive frames, namely the vehicle speed, should be at least 1 and at most 8 (MAX_SPEED).
Speed is measured in number of columns per frame.
New vehicles entering into a lane always show up in the first column of the lane, with an initial speed of 1.
STRUCTURES
Four structures are used in this project: Video, Frame, Vehicle and VehicleFrameInfo. The four structures are described briefly below. For detailed
definitions of these structures, please refer to the provided structure.h file.
Video is a structure holding all video information, including the total number of frames (num_frames), the number of frames in the frame. list
(num_processed_frames), and the processed vehicle number (num_vehicles). It also contains the pointer to all image data (raw_data), the pointer to
the first frame. (first_frame) and an array of pointers to all vehicles (vehicles). Note that all frames in this video is chained up by a link list structure.
Frame. is a structure describing one video frame, including the frame. index (index), frame. data (image), number of vehicles in this frame
(num_vehicles), the array of pointers to all vehicles in this frame. (vehicles), and the pointer to the next frame. (next_frame) in the link list structure.
Vehicle is a structure describing one vehicle, including the vehicle's appearance order in the video (index), the next appeared vehicle (next_vehicle),
the number of frames this vehicle shows in (num_visible_frames), and its information in all visible frames which is chained by a link list structure
(first_frame_info).
VehicleFrameInfo is a structure describing the information of one vehicle in one visible frame, including the index of the vehicle (vehicle_index), the
index of the frame. (frame_index), the row and column coordinates (position), and the speed of the vehicle (speed). For one vehicle, its information in all
frames are chained by a link list structure (next_frame_info).
The following figure shows the connections between the four structures. The "VF_info" indicates the VehicleFrameInfo structure. The 1D array pointed by
Video represents the Video.vehicle in Video structure, and the 1D array pointed by each frame. represents the vehicles in Frame. structure. Also in these
1D arrays, "v
i
" represents the pointer to Vehicle i, "n" the nullptr, "..." the remaining nullptr pointers. Please study this figure together with the
structure.h file before starting your implementation. Mishandling the pointers in these structures will result in segmentation faults in your program.
Web view Printable viewCourse homepage ++ Font size‐‐ Font size
COMP2011
Introduction to Objectoriented Programming
2017/11/22 COMP2011 Assignment 3: Video Monitoring
https://course.cse.ust.hk/comp2011/assignments/PA3/# 2/4
WORKFLOW
The main.cpp file provides a program for processing the video in a framebyframe. manner. We have provided the input/output interfaces in the
main.cpp and the program will read the video, process each frame, output the video information and clean up all memories allocated. To process each
frame, the program will do the following:
Initialize a new frame. in the video.
Track all vehicles in the previous frame. and the new frame. (if the new frame. is not the first frame)
Update information (of vehicles from the previous frame) in the new frame.
Detect new vehicles in the new frame. and add them and their information to the video.
Please study the workflow of the program before starting your implementation. You can test the corresponding windows executable with the input video
by putting them in the same folder. The print out in the console should be:
Reading video file. Totally 5 frames. Finished.
Frame. 0 info:
vehicle 0 in coordinate (1, 0) with speed of 1
vehicle 1 in coordinate (5, 0) with speed of 1
Frame. 1 info:
vehicle 0 in coordinate (1, 3) with speed of 3
vehicle 1 in coordinate (5, 8) with speed of 8
vehicle 2 in coordinate (3, 0) with speed of 1
vehicle 3 in coordinate (7, 0) with speed of 1
Frame. 2 info:
vehicle 0 in coordinate (1, 7) with speed of 4
vehicle 1 in coordinate (5, 16) with speed of 8
vehicle 2 in coordinate (3, 4) with speed of 4
vehicle 3 in coordinate (7, 3) with speed of 3
vehicle 4 in coordinate (5, 0) with speed of 1
Frame. 3 info:
vehicle 0 in coordinate (1, 12) with speed of 5
vehicle 1 in coordinate (5, 24) with speed of 8
vehicle 2 in coordinate (3, 8) with speed of 4
vehicle 3 in coordinate (7, 6) with speed of 3
vehicle 4 in coordinate (5, 1) with speed of 1
Frame. 4 info:
vehicle 0 in coordinate (1, 16) with speed of 4
vehicle 2 in coordinate (3, 13) with speed of 5
vehicle 3 in coordinate (7, 9) with speed of 3
vehicle 4 in coordinate (5, 2) with speed of 1
vehicle 5 in coordinate (1, 0) with speed of 1
Vehicle 0 info:
in frame. 0 in (1, 0) with speed of 1
in frame. 1 in (1, 3) with speed of 3
in frame. 2 in (1, 7) with speed of 4
in frame. 3 in (1, 12) with speed of 5
in frame. 4 in (1, 16) with speed of 4
Vehicle 1 info:
in frame. 0 in (5, 0) with speed of 1
in frame. 1 in (5, 8) with speed of 8
in frame. 2 in (5, 16) with speed of 8
in frame. 3 in (5, 24) with speed of 8
Vehicle 2 info:
in frame. 1 in (3, 0) with speed of 1
in frame. 2 in (3, 4) with speed of 4
2017/11/22 COMP2011 Assignment 3: Video Monitoring
https://course.cse.ust.hk/comp2011/assignments/PA3/# 3/4
in frame. 3 in (3, 8) with speed of 4
in frame. 4 in (3, 13) with speed of 5
Vehicle 3 info:
in frame. 1 in (7, 0) with speed of 1
in frame. 2 in (7, 3) with speed of 3
in frame. 3 in (7, 6) with speed of 3
in frame. 4 in (7, 9) with speed of 3
Vehicle 4 info:
in frame. 2 in (5, 0) with speed of 1
in frame. 3 in (5, 1) with speed of 1
in frame. 4 in (5, 2) with speed of 1
Vehicle 5 info:
in frame. 4 in (1, 0) with speed of 1
The average speed of this road: 3.33333
IMPLEMENTATION AND MARKING
You are expected to complete 9 required functions according to the specification. The function names and corresponding marks are given in the following
chart. For detailed requirements of each function, please refer to the description in front of each function in pa3.cpp file.
Functions Mark
Frame. * GetFrame(const Video & video, const int frame_index); 10
Vehicle * GetVehicle(const Video & video, const int vehicle_index); 10
VehicleFrameInfo * GetVFInfo(const Vehicle * vehicle, const int frame_index); 10
bool InitializeNewFrame(Video & video); 10
VehicleFrameInfo * TrackVehicle(const Vehicle * vehicle, const Frame. * current_frame, const Frame. * prev_frame);10
bool AddVFInfo(Video & video, VehicleFrameInfo * vehicle_frame_info); 10
bool FindAndAddNewVehicles(Video & video); 20
double AverageRoadSpeed(Video & video); 10
void CleanVideo(Video & video); 10
As mentioned, in order to check if your implementation is correct, we have provided a driver program in main.cpp and an input video.txt for testing.
Simply run the program you will be able to print out the result, which should be identical to the output in the Description section. Please be reminded
that this program is for simple reference only. In grading the assignment, we will write test programs for each of the required functions and test them
individually and in various combinations.
Please note the following:
You are required to implement all the above functions in pa3.cpp.
You are responsible for the correctness of each individual function, as we will grade them individually.
You'd better understand the four structures in structure.h and the program workflow in main.cpp before your implementation.
You are not allowed to change the function prototypes or overloading them.
You can add helper functions if you wish.
You are required to manage all memories* according to the structure figure shown in the Description section. A general rule for memory
allocation/deallocation is: one new, one delete; one new[], one delete[]. Another good practice of pointer is to set all undefined pointers (e.g.,
when initialization or after deletion) to nullptr, and check if the pointer is nullptr before using it.
You must not to use any input/output functions (cin/cout or other similar) in the program or you may lose all marks.
You are only allowed to submit pa3.cpp. You cannot change the structure.h or the main.cpp. You cannot copy the code from structure.h or
main.cpp to pa3.cpp.
*We will check the memory leak problem with several test cases. If there is memory leak in your implementation you will get a 10 point deduction.
DEADLINE
23:59:00 on Nov 29, 2017 (extended).
CASS SUBMISSION
Submit only the 'pa3.cpp' via the CASS submission page. The file names have to be exactly the same (lower case for all letters), and you
should NOT zip/compress the files.
Make sure your source files can be successfully compiled with the project. Your program has to be able to be compiled and run in the Eclipse
environment on our lab machines. If we cannot even compile your source files, your work may not be graded.
After you successfully login to CASS submission page, you should
1. Choose the course code: "COMP2011"
2. Choose the assignment name: "assignment3"
3. Select the correct path in your computer to upload the "pa3.cpp" file, and then click 'Submit"
To make sure you have submitted your program successfully, you can check the CASS log by choosing comp2011 assignment3 on the CASS system, and
then click the "Check Log" button.
You may submit your files multiple times, but only your last submission will be graded.
LATE SUBMISSION POLICY
There will be a penalty of 1 point (out of a maximum 100 points) for every minute you are late. For instance, since the deadline of assignment 3 is
23:59:00 on Nov 26, if you submit your solution at 1:00:00 on Nov 27, there will be a penalty of 61 points from your assignment 3. However, the
lowest grade you may get from an assignment is zero: any negative score after the deduction due to late penalty (and any other penalties) will be reset
to zero.
FREQUENTLY ASKED QUESTIONS
Answers to some FAQs may be posted here to clarify the assignment requirements.
2017/11/22 COMP2011 Assignment 3: Video Monitoring
Last updated: Nov 8 12:19 a.m.
Page maintained by Yao Yao | Course homepage