Friday, December 6, 2013

Step 3: (Solution 2) C++ System( ) Function

I have rewritten my code again to test the program's ability to utilize both the Libfreenect and OpenNI/PCL libraries. I have used the pipe( ) function as described in the last post, but I was told that this is unnecessarily complicated for what I need the code to do and, most importantly, I need the code to be automatized, that is, I need the code to be able to move the Kinect motor with pretested values and capture point clouds and save them according. After looking through some C++ documentation and books, I have found a function that will simplify my work: the system( ) function.

The system( )  function invokes the command processor to execute a command. Based on the programming environment (I am currently using Linux for this project), the commands can be different for different cases. For my project, I have created executable programs to move the Kinect motor to the appropriate angle and to save point clouds to a file with a specific file name. Theoretically, the libraries are not in the same program, but I am still able to utilize both libraries in the same program.

To achieve this, I had to change the overall structure of the OpenNISaveFrame header file. I had to edit the OpenNISaveFrame constructor in order for the file name to be changed from case to case. This was for simple trivial to do. Next, I had to set up the save.cpp program to read in a string from the command line, the string, of course, being the file name. Also, due to the unreliable connection between the OpenNI library and the Kinect, I have to initialize the signal twice per program execution.

Here are some pictures of the point clouds from the cloud_viewer:
Point Cloud taken at 10 degrees



Point Cloud taken at 20 degrees



The code does in fact work, but not perfectly. For some reason, when I tested the program, there were still times when the program would not initialize a point cloud would not be captured and saved into a file. I was able to compensate for this by saving point clouds for every angle twice per run. This step seems to fix that problem. Unfortunately, the run time of the program is affected as the time complexity per run increases. I will continue to work to make the program more efficient by saving point clouds to memory instead of saving to disk.

**UPDATE: I was able to get the code to work more efficiently. First, I was able to get the signal between the OpenNI and the Kinect to be more consistent by implementing the sleep ( ) function after the initialization of the interface. This allowed the signal enough time set up the connection with the Kinect before the rest of the program executed. Due to this, I only have to initialize the connection once per run instead of twice per run.  Secondly, I was able to set up the OpenNISaveFrame header file so that the point cloud captured from the Kinect saves to memory instead of saving to disk. This makes the code execute faster as it takes less time to save to memory than to save to disk. **

No comments:

Post a Comment