Docsity

Algorithms Flow Chart in Final Examination | 332 472, Exams of Electrical and Electronics Engineering

Partial preview of the text

Download Algorithms Flow Chart in Final Examination | 332 472 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

Robotics and Computer Vision

Antonio Osorio Joseph Blocker 7 May 2009 Final Report Group 8

Table of Contents:

    1. INTRODUCTION
      • Figure 1.1 Algorithm Flow Chart:
    1. EQUIPMENT
    1. Tasks
      • Table 3.1 List of Tasks............................................................................................................
    • Individual Contributions:
    1. CAMERA CALIBRATION
      • Figure 4.1 Checkerboard with the corners extracted
      • Figure 4.2 Mosaic of Left Cam. Images:
      • Figure 4.3 Mosaic of Right Cam. Images:
      • Figure 4.4 Graph of extrinsic parameters of the stereo camera system
    1. 3-D RECONSTRUCTION
      • Figure 5.1 Left Cam Image
      • Figure 5.2 Left Cam Image after Canny
      • Figure 5.3 Bad Left Image for Stereo
      • Figure 5.4 Good Right Image for Stereo:
    1. LINE FOLLOWING
      • Figure 6.1 Line Following Image:
      • Figure 6.2 Image after Edge Detection:
      • Figure 6.3: Image after Crop with Noise:
      • Figure 6.4 Image after Noise Removed:
    1. OBSTACLE DETECTION & LANE CHANGING
    • 7.i Obstacle Detection
      • Figure 7.i.1: Image Taken From Left Cam:
      • Figure 7.i.2: Image After Object Isolated:
      • Figure 7.i.4: Image After Object Isolated:
      • Figure 7.i.1 Plot of Distance Traveled vs. Time
    • 7.ii Lane Changing
    1. APPEARANCE BASED RECOGNITION & SIFT................................................................
    • 8.i Appearance Based Recognition
      • Figure 8.i.1 Successful Match Using Eigenspaces
      • Figure 8.i.2: Unsuccessful Match Found Using Eigenspaces:..............................................
    • 8.ii Scale-Invariant Feature Transform
      • Figure 8.ii.1: Successful Match Using Sift
      • Figure 8.ii.2: Sift Plot with no Match Found:
    • 8.iii Analysis
      • Figure 8.iii.1 Set of 5 Training Images
      • Figure 8.iii.2 Graph of Percentage of Good Matches vs SIFT Threshold
      • Figure 8.iii.3 Graph of Percentage of Bad Matches vs SIFT Threshold...............................
    1. CONCLUSIONS......................................................................................................................
    1. Trends in Robotics and Computer Vision..............................................................................
    1. BIBLIOGRAPHY:
    1. MATLAB CODE:

While GoSign=

Take Left and Right Pics

Run SIFT looking for ‘Go’ sign

Is ‘Go’ sign detected

GoSign=

No

Yes

GoSign=

GoSign=

While StopSign=

Stopsign=

StopSign=

CopCarDet= StopSign=

GoSign=

Ask user which lane the robot is currently in to get CurrentLane (0=Left,1=Right)

Take Left and Right Pics

Run SIFT looking for ‘Stop’ sign

Is ‘Stop’ sign detected

Yes

StopSign =

No

If CopCarDet= Run SIFT looking for Police car

Is Police detected

Play Warning Tone

CopCarDet=

True

False

Check For obstacle

This is Done to determine which camera will be used to follow the line

Is there an obstacle?

Since SIFT takes a long time to run we look for the police car only if it has not already been found

Call LineFollower and let it run for the default seconds

Calculate Distance to the object

Determine the amount of time for the robot to move forward before turning

Call LineFollower and let it run for the determined amount of time

Change Lanes Update CurrentLane

Display “StopSign Detected’ Terminate Program

Figure 1.1 Algorithm Flow Chart: The figure above gives a high level view of how the vision based line following, obstacle detection, lane changing, and image based recognition fit together to achieve the goals of the project.

2. EQUIPMENT

  • Lego Mindstorm NXT

  • MATLAB 7.

  • 2 Logitec Notebook Webcams

  • Electrical Tape

3. Tasks

Table 3.1 List of Tasks Goals Accomplished Vision Based Line Following Yes Change "lead" Camera based on Current Lane Yes Change Lanes Yes Perform Stereo Calibration Yes Detect Obstacles Yes Determine If Obstacles are in Current Path Yes Vision Based Object Recognition Yes 3-D Reconstruction Partially

4. CAMERA CALIBRATION

We used the MATLAB Camera Calibration Toolbox provided by Caltech for camera calibration. The toolbox takes images of a checkerboard, (a plane with a repeating pattern and clear identifiable corners), to perform calibration. The images of the checkerboard are taken with different orientations with respect to the origin of the plane, then the grid corners are identified in each image, and finally, the toolbox calculates the calibration parameters (M (^) intrinsic and M (^) extrinsic) based on the given data. Figure 4.1 below shows the checkerboard with the corners extracted and dx and dy (dz is simply the cross product of dx and dy).

O dX

dY

Xc (in camera frame)

Yc (in camera frame)

Extracted corners

50 100 150 200 250 300

50

100

150

200

Figure 4.1 Checkerboard with the corners extracted : The figure above shows the results that the Caltech camera calibration toolbox generates when it extracts the corners of the checkerboard image. It does this for all of the corresponding image pairs of images from the left camera and right camera (discussed below), and based on the matching pairs between them, finds the rotation matrix and translation vector of the right camera with respect to the left camera.

The main parameters of interest that are generated are the rotation matrix of the world with respect to the camera (l^ Rw), the translation vector of the world with respect to the camera ( l^ Tw ) (^) ,the focal length (f), and the camera center (ox ,oy). (The effective pixel size (sx ,s (^) y) is assumed to be 1 mm x 1mm).

In order to perform stereo calibration with the CalTech toolbox, single camera calibration was performed on 10 image pairs (pictures taken from the left and right cameras simultaneous for each given orientation of the checkerboard). Figures 4.2 and 4.3 below show 20 images used for stereo calibration.

Calibration images

Figure 4.2 Mosaic of Left Cam. Images: The above 10 images were used to get the intrinsic parameters of the left camera and then to perform stereo calibration to get the rotation matrix and translation vector of the left camera with respect to the right camera

Calibration images

Figure 4.3 Mosaic of Right Cam. Images: The above 10 images were used to get the intrinsic parameters of the left camera and then to perform stereo calibration to get the rotation matrix and translation vector of the left camera with respect to the right camera

These results were then saved and used for the Caltech stereo calibration. The results of the stereo calibration yielded the parameters (the rotation vector of the left camera with respect to the right camera ( rRl ) and the translation vector ( rTl ) of the left camera with respect to the right camera, camera centers (ox ,oy), and the focal lengths of the two cameras) necessary to retrieve the 3-D camera coordinates from corresponding pairs of image coordinates. The parameters generated from the 20 images were found to be:

rRl = [0.9953 0.0377 -0. -0.0329 0.9980 0. 0.0910 -0.0514 0.9945]

rTl = [ -113.77144 ; 2.52426 ; -6.04414 ]

f (left)= 404.87488 +/- 6. [ox oy ] (left) = [ 161.38072 124.70858 ] ± [ 18.95467 14.02291 ]

f (right) = 408.63417 ± 6. [ox oy ] (right) = [ 181.81518 108.05556] ] ± [ 17.32899 12.58300 ]

And the distance between the two cameras was found by taking the magnitude of the rTl

| rTl | = norm( rTl ) = 113.9598 mm (since 1 pixel ~ 1mm)

5. 3-D RECONSTRUCTION

Our goal for the use of stereo reconstruction was to first use SIFT to recognize a triangular “Go” sign (just as depicted in Figure 1.1), and then use stereo reconstruction to determine the absolute length of its base from its 3D camera coordinates. If the length was correct, then the program was to be started. We planned to test this by using two “Go” signs that differed only in their scale. Then we would show that the robot driving program would only start if the correct size “Go” sign was detected. The largest problem we encountered was trying to get the correct corresponding pairs. Our methodology was to use a canny edge detector to find the edges of the triangle, remove the background edges, and then find the coordinates of the pixel that had the shortest distance to each of the bottom edges. The code to find the corresponding pairs simply looks at all of the white pixels when the background has been removed (see Figures 5.3 and 5.4 on the next page), and measures the distance between those points and the two lower corners of the frame. Once the distances between all of the white pixels and the two lower corners of the left and right camera frames are found, the pixels with the minimum distance are recorded. These two points correspond to the left and right corners of the “Go” sign triangle. If the entire background was removed, the corresponding pairs of the left and right camera are found, and the absolute length of the bottom edge of the triangle could be determined from the 3D points in camera coordinates. The problem we encountered was trying to get all of the background noise removed. Figure 5. shows how having only a tiny bit of noise will result in finding incorrect corresponding pairs, and thus stereo reconstruction will not provide accurate results. We adjusted the threshold of the edge detection but to no avail. The resulting distance error ranged any where from 20% to well over 100% depending on whether the corresponding pairs where accurate or not. Unfortunately we were unable develop an algorithm that would reliably find correct corresponding pairs. Especially due to the fact that the cameras are pointed toward the ground (for line following) and the triangle could only be in the top 1/5 of the frame. Therefore the size of the triangle with respect to the whole frame was small. And since the resolution of the cameras is so low, getting accurate results was further complicated.

Figure 5.2 Left Cam Image after Canny The image in Fig. 1 was passed through a Canny edge detector with a high threshold to remove most of the background noise.

Figure 5.1 Left Cam Image The image above is from the left camera with the triangle 100 cm away from the camera.

Figure 5.3 Bad Left Image for Stereo The image above is the result of filling in all of the imfill() and imclearborder(). These steps were taken to further remove the noise. The few white pixels to the far left of the triangle above are found as being the closest to the far left corner. This results in extremely poor result for the absolute length of the triangle since this far left pixel is matched to the correct corner from Figure 5.

Figure 5.4 Good Right Image for Stereo: The image above is from the exact scene as the in Figure 4.3 but it is taken with the left camera. Since the correct corresponding pairs were not found, the resulting absolute length was calculated incorrectly.

Figure 6.2 Image after Edge Detection: A After canny edge detection with a high threshold is is applied, only dominant lines are present. Most of t the background noise has been removed.

Figure 6.1 Line Following Image: This image was taken from the left camera when the Robot was in the left lane.

X: 145 Y: 24 Index: 0 RGB: 0, 0, 0

X: 133 Y: 25 Index: 0 RGB: 0, 0, 0

Figure 6.3: Image after Crop with Noise: The location marked in the figure above is the calculated center of gravity with the noise present on the left.

Figure 6.4 Image after Noise Removed: After the noise is removed the true center of gravity of the line is found. Comparing this Figure to Figure 6.3 shows that even with a small amount of noise the center of gravity is not shifted so far that the robot will go off course.

The line following algorithm described above is implemented in a simple loop that continuously sends updated motor settings to the robot for a fixed amount of time. The default amount of time the robot moves is 4 seconds (if no obstacle is detected).

7. OBSTACLE DETECTION & LANE CHANGING

7.i Obstacle Detection

Obstacle avoidance is one of the most important aspects of any autonomous mobile robot. Without being able to determine a safe path of travel, the robot movement would be restricted only to motion along a known obstacle-free path. Since there are varieties of obstacles that could present themselves, it would be impractical for our project, and in real world practice, to perform

object recognition on every possible object. Therefore, we are not actually “detecting” an object

  • we are instead detecting any solid object in the robot’s path.

Due to the slow shutter speed of the webcams, getting focused shots of the environment is nearly impossible if the robot is moving. Our options were to either move the robot incredibly slow, or to stop the robot from moving before it captures an image and use our stereo vision setup to find the distance to the obstacle and calculate a path around it. The latter method was chosen. Figures 7.i.1-7.i.2 below show the same type of object isolation used for finding the corresponding pairs of the triangular “Go” sign. Since the robot is not moving at this point the background subtraction works sufficiently well.

Figure 7.i.1: Image Taken From Left Cam: The above image is taken with the left camera of an obstacle in the path of the robot.

Figure 7.i.2: Image After Object Isolated: The figure above is generated after the image from Figure 7.i.1 is sent through a Canny edge detector, solid masses filled, and the borders cleared. The resulting image is approximately the obstacle only.

Figure 7.i.3: Image From Right Cam: The above image is taken with the right camera of an obstacle in the path of the robot.

Figure 7.i.4: Image After Object Isolated: The figure above is generated after the image from Figure 7.i.3 is sent through a Canny edge detector, solid masses filled, and the borders cleared. The resulting image is approximately the obstacle only

Obstacle Detection Methodology:

7.ii Lane Changing

Lane changing was done by sending a command to the robot to turn 90 degrees, move forward, and turn 90 degrees in the opposite direction. Although this task may seem trivial, getting the robot to turn the correct amount proved quite difficult. Since the motors are not perfectly synced, and the friction of the tape on the ground is different from the floor tiles, the robot could turn anywhere from 70 degrees to 110 degrees using the same command. Fortunately our line following algorithm is able to get the robot back on track. And since the line following command is called for 3 seconds after any turn, by the time the obstacle detection algorithm is called the robot is facing in approximately the right direction. Occasionally this would break down if one of the wheels got stuck on the tape and the line would be out of view of the line following camera.

8. APPEARANCE BASED RECOGNITION & SIFT

8.i Appearance Based Recognition

For our purposes, the robot needs to clearly identify whether a police vehicle is somewhere in the scene. Originally, we planned to implement this with object recognition via finding object eigenspaces. We used modified versions of the algorithms in the textbook to create the image eigenspaces and to indentify images based on the eigenspaces. The algorithm to create the image eigenspace is as follows:

  1. Take n images of the object to be recognized at the same distance but with different orientations (since the robot is driving on a road, it has to be able to identify a police vehicle from the rear and possible the side; therefore, we only need orientations of the vehicle from the rear and sides)
  2. Crop out the desired object to be recognized with each cropped images dimensions forming a perfect square matrix – N x N
  3. Convert the cropped images from RGB to Grayscale and then convert the matrices into column vectors of dimension N^2 x 1
  4. Form a matrix, T, composed of each of the individual vectors – T is a N^2 x n matrix
  5. Find the average of the entire matrix, then subtract the average from each column vector to form a new matrix T - average
  6. Find the covariance matrix, C, of the original matrix T and T – the average
  7. From the covariance matrix, compute the eigenvalues and retain the largest
  8. Project the images onto the eigenspace by multiplying the largest eigenvalue by each column in the T – average matrix

This training process creates the image eigenspace of training images to be used for object recognition. When a new image is acquired that contains an object to be recognized, the following algorithm is implemented to determine if the object is present:

  1. Crop out the desired object to be recognized with the cropped image having the same dimensions of the training images dimensions, N x N
  1. Convert the cropped image from RGB to Grayscale and then convert it to a column vector of dimensions N^2 x 1
  2. Subtract the average of the training set database from the image and then project the image onto the image eigenspace by multiplying the image by the largest eigenvalue of training set database
  3. Find which training image eigenspace point is closest to the desired image eigenspace point a. If the closest image point distance is beneath a certain threshold, it is determined that the object has been recognized (it is part of the database) b. If the closest image point distance is above the given threshold, the object was not recognized as part of the database

By implementing these algorithms, we have set up the robot to be able to identify a police vehicle in the scene. The following two figures show the results of this process. The first figure shows a police vehicle was correctly identified. In this case, the new image was part of the training database and found an exact match. The second figure shows the best match to finding a police vehicle. The new image was not part of the database and therefore an exact match was not found.

Figure 8.i.1 Successful Match Using Eigenspaces : Using image eigenspaces, we attempted to find a police vehicle. We compared the image of interest with the images in the training set and found an exact match. The image we were looking for is on the left and the image found is on the right.

Figure 8.ii.1: Successful Match Using Sift : This figure shows the results of using SIFT to successfully detect a police vehicle. The percentage of good matches vs. total matches (the green lines) is quite high, and therefore it is determined that a police vehicle has been found.

Figure 8.ii.2: Sift Plot with no Match Found: This figure shows the results of using SIFT to successfully not detect a police vehicle. There are no matches (green lines) between the real time image and the training image. It is therefore determined that no police vehicle is the scene, and that is correct.

8.iii Analysis

As mentioned earlier, when using SIFT, hundreds, if not thousands of potential matches are found between images if the threshold value is too low. This was a source of error when implementing SIFT. We used the number of matches found to determine if a police vehicle was detected or not and if this number was too large, then an incorrect detection could arise. For instance, in Figure 8.ii.2, no matches are found. If the threshold value for SIFT was lowered, however, hundreds of matches would be present and an incorrect police vehicle detection would occur. It was necessary to determine the threshold value that gives the best percentage of correct matches to determine whether a police vehicle is present or not. The following figures shows this analysis. Using the selected training images, the percentage of good matches vs. the threshold value was plotted in the first figure. Alternatively, the second figure plots the error, or percentage of bad matches, vs. the threshold value.

Figure 8.iii.1 Set of 5 Training Images : The pictures above are the five training images used in the analysis in Figure 8.iii.2 below. The images are shown in ascending order.

Figure 8.iii.2 Graph of Percentage of Good Matches vs SIFT Threshold : This plot shows the percentage of good matches found using SIFT versus the threshold value in SIFT. The threshold value is raised and the percentage of good matches increases. Note: Based on this data, the threshold value we used is 3. Also, the best orientation for a police vehicle is one that closely resembles Training Image 1 as it gives the highest percentage of good matches at almost every threshold value. The least favored orientation is one that resembles Training Image 2 as it has the lowest percentage of good matches at every threshold value.