Graduated Self-Driving Car Engineer Program from Udacity.

I have completed all of the requirements of the Self-Driving Car Nanodegree Program and have officially graduated on February 11, 2019. In the last year two years, I have built projects in computer vision, deep learning, sensor fusion, localization, path planning, control, and system integration. I have worked so hard to complete projects and develop my skills. I am so proud of myself.

 

OpenCV 3.1.0 install on Jetson TX1

I used following references.

  • Installation of opencv-3.1.0 on Jetson TX1 [here]
  • Installing OpenCV 3.1.0 [here]
  • minhoolee/install-opencv-3.1.0.sh [here]
  • dselivanov/scripts-ubuntu-debian [here]

Uninstall the current OpenCV

  • $ sudo rm -rf /usr/local/include/opencv
  • $ sudo rm -rf /usr/local/include/opencv2
  • $ suro rm -rf /usr/local/lib/python2.7/dist-packages/cv2.*
  • $ suro rm -rf /usr/local/lib/python3.5/dist-packages/cv2.*
  • $ sudo rm /usr/local/lib/libopencv_*

You need to change the Python version numbers if you are using different ones.

Keep Ubuntu up to date

  • $ sudo apt-get -y update
  • $ sudo apt-get -y upgrade
  • $ sudo apt-get -y dist-upgrade
  • $ sudo apt-get -y autoremove

Install development libraries

  • # Add universal repository to Ubuntu
  • $ sudo apt-add-repository universe
  • $ sudo apt-get update
  • # Some general development libraries
  • $ sudo apt-get install -y build-essential make cmake cmake-curses-gui g++
  • # libav video input/output development libraries
  • $ sudo apt-get install -y libavformat-dev libavutil-dev libswscale-dev
  • # Video4Linux camera development libraries
  • $ sudo apt-get install -y libv4l-dev
  • # Eigen3 math development libraries
  • $ sudo apt-get install -y libeigen3-dev
  • # OpenGL development libraries (to allow creating graphical windows)
  • $ sudo apt-get install -y libglew1.6-dev
  • # GTK development libraries (to allow creating graphical windows)
  • $ sudo apt-get install -y libgtk2.0-dev
  • # Install unzip and wget
  • $ sudo apt-get install -y unzip wget

Download and install OpenCV

  • # Download
  • $ cd ~/Downloads
  • $ wget https://github.com/opencv/opencv/archive/3.1.0.zip
  • # Unzip
  • $ unzip 3.1.0.zip
  • $ rm 3.1.0.zip
  • # Prepare for building
  • $ cd opencv-3.1.0
  • $ mkdir build $ cd build
  • # Building
  • $ cmake -DWITH_CUDA=ON -DCUDA_ARCH_BIN=”5.3″ -DCUDA_ARCH_PTX=”” -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCUDA_FAST_MATH=ON ..
  • $ make -j4
  • $ sudo make install
  • # Setup
  • $ sudo /bin/bash -c ‘echo “/usr/local/lib” > /etc/ld.so.conf.d/opencv.conf’
  • $ sudo ldconfig

OpenCV issues in Anaconda

When an error message is shown from a python code using cv2 (opencv), the message is most likely misleading. The message is saying nothing but something is wrong. All the details in the message are not what you need to do to fix the problem.

I had issues with VideoCapture and imshow. The error messages look explanatory but they are not. All problems were stemmed from a python wrapper package that I installed through pip.

$pip uninstall opencv-python

Your conda must have one opencv version. In my case, the version is 3.2.0 that was built from source code where I enabled FFMPEG to fix VideoCapture problem.

 

C scanf with comma separated values.

Unlike scanf function family in MATLAB, C scanf doesn’t consider the comma(,) as a delimiter for the specifier “%s.”

Let’s say we have a data file as follows.

Spiderman,Parker,99<br />Superman,Ken,89<br />Batman,Wayne,79

The following code will not work. The variable “first_name” will have the whole line “Spiderman,Parker,99” since it thinks there is no delimiter in the line.

char first_name[50], last_name[50];<br />int grade;<br />FILE *fp = fopen("data.csv", "r");<br />fscanf(fp, "%s,%s,%d\n", first_name, last_name, &amp;grade);

Here is a way to make scanf functions think the comma (,) is a delimiter.

fscanf(fp, "%[^,],%[^,],%d\n", first_name, last_name, &amp;grade);

fscanf in MATLAB

Unlike in C/C++, fscanf in MATLAB repeats the scanning as long as the formatted text matches. It is convenient but also confusing sometimes.

For example, in a text file there are lines as follows.

Image Width Height: 800, 600
Red X Y Radius: 200, 300, 300
Green X Y Radius: 300, 400, 200
Blue X Y Radius: 500, 500, 150

We can read the first line using
dim = fscanf(fid, '%*s %*s %*s %d, %d\n');             (a)

A problem arises after this scanning since it tries to scan the next line as well with the format that is given. So even if you try to read the next line with the fscanf (b), the scanning will fail since the fscanf in (a) tries to scan the next line.
redc = fscanf(fid, '%*s %*s %*s %*s %d, %d, %d\n');    (b)

So in this specific case, it is better to use the followings.
dim  = fscanf(fid, 'Image Width Height: %d, %d\n');
redc = fscanf(fid, 'Red X Y Radius: %d, %d, %d\n');
grnc = fscanf(fid, 'Green X Y Radius: %d, %d, %d\n');
bluc = fscanf(fid, 'Blue X Y Radius: %d, %d, %d\n');

There are better ways but this would be quick fix.

No Console Output in Eclipse with CDT in Windows

In Windows the Console doesn’t display any output from printf. Let’s see an example.

int main(void) 
{
    int i;

    printf("Enter a number: ");
    scanf("%d", &amp;i);
    printf("You entered %d\n", i);
    return EXIT_SUCCESS;
}

The text “Enter a number: ” is not shown in the Console windows of Eclipse with CDT. This is due to the fact all the stdout and stderr ouputs in Windows are buffered. So we can simply flush stdout and stderr everytime you use printf. But it is not practical solution. You may add these two lines of code in the first part of your main function.

  • setvbuf(stdout, NULL, _IONBF, 0);
  • setvbuf(stderr, NULL, _IONBF, 0);

These lines enforce stdout/stderr not to have buffers which means that all the output will be happening as soon as it takes place. One serious problem of this solution is that the program will be crashed if you start the debugger and try to step over any of printfs. So in the Debug mode, starting a new command prompt console is a good idea. Let’s me summary this workaround.

Use setvbuf for Run mode

Put this function in your main function in the first place.

void set_std_buffer_off()
{
    setvbuf(stdout, NULL, _IONBF, 0);
    setvbuf(stderr, NULL, _IONBF, 0);
}
int main(void)
{
    // turn off the std buffering
    set_std_buffer_off();

    // start your own code.
    ....
}

You now see outputs from printfs in your code when you run the program.

Debug mode

For the debug mode, use GDB command file.

Create a text file and named it as “gdbinit.txt” The file name is not important anyway. You may use any proper name. Open the text file and put this single line into the file and save it.

<span style="line-height:1.5em">set new-console on</span>

This line simply means that new console will be started when the debugger starts a debugging session.

Open “Preferences” (Window > Preferences). Set the text file for “GDB command file:” in C/C++ –> Debug –> GDB. Click the “Apply” button and the “OK” button.

Try to debug your program. Then you will see a command prompt when the debugger starts. All outputs and inputs will be happening in the new command prompt without having any troubles.