I have built PCL from source and installed it in my Ubuntu 14.04. Everything was fine till these days.
I wanted to rebuild one of my test code in which I used Xition as the input device and it needed OpenNI2. When running ``make'' the system complained that it couldn't find pcl/io/openni2_grabber.h. I checked and found the head file was in the source package but not in the corresponding system folder. So it was something wrong with the make files.
The solution is to turn on the flag BUILD_OPENNI2 which has OFF as the default value[1]. I used
$ grep -r "BUILD_OPENNI2" .
to find it was in the file of CMakeCache.txt. Then just changed the value of from OFF to ON and did make && sudo make install again.
The course had been closed in several months ago, but I didn't get enough leisure time (and proper mood... maybe...) to complete the robot until these weeks. The following photos show the QuickBot:
Front view of my QuickBot
Top view; the BBB is on the left side
The mess of wires between the chassis
What I have done so far is to test the sensors and motors with the help of the testing code qb_test written by Mike Kroutikov. Because I've used the Sharp GP2Y0A41SK0F IR sensors which are different from the ones assigned in the course, I am not sure whether the output is identical to that given in the comment of the test code. Therefore, after some tests, I decided to modify the test code for the IR sensors to show the detected distances in centimetres[3].
I searched and found some conversion formulas for Arduino[2]:
The trend of the output seemed right, but the absolute values were far from accurate. I might have to do some tests to find my own formula.
What I failed in the test was the communication between the host PC (running pysimiam) and the QuickBot's BBB (running quickbot_bbb). I have Wi-Fi adaptor connected to the BBB and it worked perfectly for accessing the internet, but I just couldn't connect the BBB wirelessly from my PC. I decided to postpone this part.
My next plans are:
To write some code to drive the motors with the IR readings as the reference;
Code is available here: https://github.com/hiankun/orb_test
Here was my test on feature matching with ORB. In the video, the target image was shown in the left side and the real-time video was in the up-right corner.
The feature points on the target image matched to the target when there were no other textured objects. If any object has detected feature points, however, the matching relationship would be disturbed significantly.
I have not test the matching approach by using SURF or SIFT features. This will be the next step.
Okay, I know it's not a big deal, but it's my first step to use git more than just a logging tool in local machines.
Actually I was slightly scared by the complexity of git, especially its mystical jargon such as rebase, merge, cherry-pick and so on.
I thought, however, the git shouldn't be just used as a logging tool locally. Also, I wanted to use GitHub as the code repository which would be convenient to people who want to check my code. By upload my code to GitHub, I don't need to copy and paste it in the blog post. That's a better and smarter approach to share source code.
Here are some basic trials in which I tested OpenCV running on my BBB.
The Logitech C920 webcam did some works which I don't know very well so that the loading on the BBB has been reduced significantly. Other webcams might too ``slow'' for the test program to run directly (I remember the terminal returned `select timeout' errors).
[NOTE: the following videos were boring and showed nothing exciting... :-p] [Sorry for the small view of the videos. I will find how to enlarge them later...]
[I've uploaded the video clips so that you can view them with better resolution.]
The first one was the result shown via VNC. The image stream was laggy, but the processing time showed it was about 100 to 200 ms.
The second one showed the result without cv::imshow() via VNC. The processing time seemed reduced, but not significantly.
The last one showed the result without cv::imshow() via ssh. The processing time was no more than 100ms.
It seemed that the VNC costed most of the computing resource.
[A brief note for my first test with the Debian image]
Actually I installed the Debian image several days ago, and did set the Wifi connection successfully. When I tried to update the system, however, the terminal replied with error message said that my system had no enough space. So I went back to Angstrom. And now I'm back to Debian again.
The Debian image was large. After the installation, I checked the disk usage by typing ``df -h''... 93% used... It's crazy.
So, after reflash the on-board eMMC of BBB, I removed something like /usr/share/doc, Chromium, and even Vim (there's vi for later usage). This time, the system updated without errors.
Step 1: Make sure the system know the Wifi adaptor. Use ``lsusb'' and the system return the detected devices. In my case, it's the line with ``Ralink Technology, Corp.''
Step 2: Check ``/etc/rcn-ee.conf'' and make sure it contain the following settings:
Step 3: Edit ``/etc/network/interfaces'' with the following settings:
auto ra0 iface ra0 inet dhcp wpa-ssid your_network_name wpa-psk your_hashed_password
Yesterday when I was trying to update the OpenCV in my BBB, a strange thing happened. After downloading and unzipping OpenCV 2.4.9 in BBB [1], I couldn't log into my BBB via ssh (but using the webpage still worked). The terminal responded nothing, and it just hanged there without logging in.
The Cloud9 IDE helped in the test. It connect to your BBB and allow you to do something with JavaScript (I tested two of them which will be listed below).
Then I tested the second script [3]. After running that script I logged in BBB via ssh again.
Actually I still have no idea what'd happened. Maybe the resource of BBB had been run out after the downloading of OpenCV? Maybe something else caused the problem.
---
Edit:
I read the mail list again and found the post which listed the second script had said something may be useful. It talked about systemd-journal settings.
---
[1] I wouldn't do it again. At the beginning, I was planning to build OpenCV 2.4.9 in my BBB. Later, I read VAT's article and knew that I should use cross-compilation.
After installing the patched fonts, you can add the following settings in the .vimrc to enable the symbols:
if !exists('g:airline_symbols') let g:airline_symbols = {} endif " unicode symbols let g:airline_left_sep = '»' let g:airline_left_sep = '▶' let g:airline_right_sep = '«' let g:airline_right_sep = '◀' let g:airline_symbols.linenr = '␊' let g:airline_symbols.linenr = '' let g:airline_symbols.linenr = '¶' let g:airline_symbols.branch = '⎇' let g:airline_symbols.paste = 'ρ' let g:airline_symbols.paste = 'Þ' let g:airline_symbols.paste = '∥' let g:airline_symbols.whitespace = 'Ξ' set guifont=DejaVu\ Sans\ Mono\ 10 let g:airline_powerline_fonts = 1
Several months ago, I've followed the course of ``Control of Mobile Robots'' on Coursera. Although I've finished the course, but the hardware part has been postponed for these months.
I determined to record the tests on the hardware, and here is the first post on the topic.
The following procedure based on the course lecture.
Step 0: I used my mobile phone as the Wifi hotspot for the BBB internet connection.
Step 1: Connect the USB cable between the BBB and the PC. Plug the Wifi adaptor as well.
Step 2: Log in BBB using ssh. Just type the follows in the terminal of host PC:
ssh 192.168.7.2 -l root
Step 3: (from now on, all the commands will be working in BBB) Use the following command to get the hashed string which will be pasted in the configuration file:
wpa_passphrase "your network name here" 'your password here'
Step 4: Paste the hashed string into /var/lib/connman/wifi.config. The content of the wifi.config looks like:
[service_home]
Type = wifi
AutoConnect = true
Favorite = true
Name = your network name
Passphrase = your hashed password
Update:
I have encountered problems in the Wifi connection when I reflash my eMMC with new Angstrom images. I tried the newest version (2013.09.04) and an old one, but got no luck.
The newer Angstrom could identify the Wifi adaptor (by using lsusb, the terminal returned a message with the Wifi adaptor's company name), but all the same settings just couldn't make BBB connecting to the internet.
Note that the WITH_IPP option had been disabled or there would be errors (which I didn't have time to tackle).
I also used lscpu to view my CPU information. Actually I didn't know anything about ``number of hardware threads,'' and I assumed it just equal to the number of CPU multiplied by ``Thread(s) per core.'' I typed ``make -j16'' during the installation.
After the installation, I check the installed version by typing
pkg-config --modversion opencv
and it returned
3.0.0
Also, in ipython, typed the following command to check the installed version:
In [1]: import cv2 In [2]: print cv2.__version__ 3.0.0-dev
That's out of my expectation. I thought the example was under the location of OpenCV 3.0.0, so it should had no problem for me to run the sample code. Another bad news was that the old StereoBM module was also failed.
---
I just tried the ORB example, but the module was also disappeared from the 3.0.0 version.
After reinstall OpenCV 2.4.9, everything was okay. So now I just have no idea where are the missing modules in OpenCV 3.0.0.
I've just installed CrunchBang in VirtualBox two days ago, but the resolution was limited so it cannot fit my monitor properly. After some trials (including some struggles when installing the so-called Guest Additions), I successfully changed the resolution to my need.
But there's some more work to do to make the change permanently. We need to add the following lines (from my own setting) in ``~/.config/openbox/autostart'':
Actually this confused me and I'm not sure about every details. Here I just write down what I've done for your reference.
The first thing I did was to insert the VBoxGuestAdditions.iso image via the GUI (I've selected the iso file before, so it appeared in the list automatically):
Then click the ``Insert Guest Additions CD image...'' or use the following command to mount the image:
mount /dev/sr0 /media/cdrom
Now we can find the ``VBoxLinuxAdditions.run'' script and run it:
In the previous post [1] I've tried the GrabCut function of OpenCV, when I noticed it was time consuming but didn't try to check the exact processing time. But I was still wondering ``how slow'' did GrabCut could be. So, I started to add the clock() function to see the result [2].
Later, I though of that the processing time was greatly affected by the image size, so I searched for functions which could reduce the images for speeding up GrabCut. What I found were cv::pyrDown() and cv::pyrUp() and they've been implemented in my test code (listed below).
#include "opencv2/opencv.hpp"
#include <iostream>
#include <time.h>
using namespace std;
const bool DOWN_SAMPLED = true;
const unsigned int BORDER = 1;
const unsigned int BORDER2 = BORDER + BORDER;
int main( )
{
clock_t tStart_all = clock();
// Open another image
cv::Mat image;
image = cv::imread("sunflower02.jpg");
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
cv::Mat result; // segmentation result (4 possible values)
cv::Mat bgModel,fgModel; // the models (internally used)
if(DOWN_SAMPLED){
// downsample the image
cv::Mat downsampled;
cv::pyrDown(image, downsampled, cv::Size(image.cols/2, image.rows/2));
cv::Rect rectangle(BORDER,BORDER,downsampled.cols-BORDER2,downsampled.rows-BORDER2);
clock_t tStart = clock();
// GrabCut segmentation
cv::grabCut(downsampled, // input image
result, // segmentation result
rectangle,// rectangle containing foreground
bgModel,fgModel, // models
1, // number of iterations
cv::GC_INIT_WITH_RECT); // use rectangle
printf("Time taken by GrabCut with downsampled image: %f s\n", (clock() - tStart)/(double)CLOCKS_PER_SEC);
// Get the pixels marked as likely foreground
cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
// upsample the resulting mask
cv::Mat resultUp;
cv::pyrUp(result, resultUp, cv::Size(result.cols*2, result.rows*2));
// Generate output image
cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
image.copyTo(foreground,resultUp); // bg pixels not copied
// display original image
cv::namedWindow("Image");
cv::imshow("Image",image);
// display downsampled image
cv::rectangle(downsampled, rectangle, cv::Scalar(255,255,255),1);
cv::namedWindow("Downsampled Image");
cv::imshow("Downsampled Image",downsampled);
// display downsampled mask
cv::namedWindow("Downsampled Mask");
cv::imshow("Downsampled Mask",result);
// display final mask
cv::namedWindow("Final Mask");
cv::imshow("Final Mask",resultUp);
// display result
cv::namedWindow("Segmented Image");
cv::imshow("Segmented Image",foreground);
}
else {
cv::Rect rectangle(BORDER,BORDER,image.cols-BORDER2,image.rows-BORDER2);
clock_t tStart = clock();
// GrabCut segmentation
cv::grabCut(image, // input image
result, // segmentation result
rectangle,// rectangle containing foreground
bgModel,fgModel, // models
1, // number of iterations
cv::GC_INIT_WITH_RECT); // use rectangle
printf("Time taken by GrabCut with original image: %f s\n", (clock() - tStart)/(double)CLOCKS_PER_SEC);
// Get the pixels marked as likely foreground
cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
// Generate output image
cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
image.copyTo(foreground,result); // bg pixels not copied
// display original image
cv::rectangle(image, rectangle, cv::Scalar(255,255,255),1);
cv::namedWindow("Image");
cv::imshow("Image",image);
// display result
cv::namedWindow("Segmented Image");
cv::imshow("Segmented Image",foreground);
}
printf("Total processing time: %f s\n", (clock() - tStart_all)/(double)CLOCKS_PER_SEC);
cv::waitKey();
return 0;
}
The key idea was to downsample the image for GrabCut and then upsample the result (I thought it was a mask) to the original size. The result showed a remarkable speeding up in both the debug and the release mode.
Here are the output images with the downsampling strategy:
Fig 1. Original image
Fig 2. Downsampled image
Fig 3. Mask obtained by using GrabCut
Fig 4. Upsampled mask
Fig 5. Final result
Here is the result without the downsampling strategy:
Fig 6. GrabCut result without downsampling
Comparing Figure 5 and 6, we can easily notice the differences between the segmented results. When applying the downsampling strategy, some image details were lost and the mask would be different and had rougher edges as well.
Although the downsampling strategy has the drawback of losing image details, the benefit of reducing processing time was significant. The following table lists the processing time obtained by using above code with and without the downsampling strategy.
As mentioned in the previous post, in which I tried the GrabCut by using the OpenCV's library. Because I didn't have libs and dlls for debug mode, so I tried to use CMake to build them for my own usage.
First I went to OpenCV website to download the latest stable version 2.4.6. The source code for Windows were packed in a exe file. Don't worry about it, just download it and click it and the 7zip will extract the whole source package for you. In my case, the extracted folder was named ``opencv''.
Then I lauched CMake GUI, chose the location where the extracted folder was located, and chose the build directory for the building files.
Click the ``Configure'' button and if everything is okay then the ``Generate'' button. In my case, I'd chosen the generator as ``Visual Studio 2005'' (at a certain step I didn't rememberd0, so the generating result contained an OpenCV.sln in the build folder.
The final step was just click the OpenCV.sln to launch the Visual Studio and then Build the project for Debug and Release mode. The products were located in the build/bin and build/lib directories.
I was considering using GrabCut to cut out the target in one of my working project. After testing it using Python, I thought it's necessary to try it in C++ code. Therefore I started to find some example code and picked one for my test [1].
Here is my test code, the sample photo, and the result:
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{
// Open another image
Mat image;
image = cv::imread("sunflower02.jpg");
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
// define bounding rectangle
int border = 20;
int border2 = border + border;
cv::Rect rectangle(border,border,image.cols-border2,image.rows-border2);
cv::Mat result; // segmentation result (4 possible values)
cv::Mat bgModel,fgModel; // the models (internally used)
// GrabCut segmentation
cv::grabCut(image, // input image
result, // segmentation result
rectangle,// rectangle containing foreground
bgModel,fgModel, // models
1, // number of iterations
cv::GC_INIT_WITH_RECT); // use rectangle
// Get the pixels marked as likely foreground
cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
// Generate output image
cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
image.copyTo(foreground,result); // bg pixels not copied
// draw rectangle on original image
cv::rectangle(image, rectangle, cv::Scalar(255,255,255),1);
cv::namedWindow("Image");
cv::imshow("Image",image);
// display result
cv::namedWindow("Segmented Image");
cv::imshow("Segmented Image",foreground);
waitKey();
return 0;
}
The sample photo used in the test
The result of applying GrabCut
During the test, I encountered an old problem to me, which had been some odd runtime bugs for the debug mode when using OpenCV. The solution might be NOT to mix up the debug and release libraries [2].
Oh, by the way, the processing time of the GrabCut was too long (about 2 seconds in the test case), and I thought it's not feasible for realtime applications. Orz
Yesterday I searched the problem on Google and found nothing useful (according to my skill level, I might overlooked something that could be hints), so I decided to ask in the G+ Python community [1].
Then I noticed a magic word ``0xFF'' in the new downloaded sample code. Using the hint, I finally found the bug report about cv2.waitKey() and came up with a tiny test code:
import cv2
import numpy as np
cv2.namedWindow('test')
while True:
#key = cv2.waitKey(33) #this won't work
#key = 0xFF & cv2.waitKey(33) #this is ok
key = np.int16(cv2.waitKey(33)) #this is ok [2]
if key == 27:
break
else:
print key, hex(key), key % 256
cv2.destroyAllWindows()
I was trying to evaluate the feasibility of a project, and Python of course was my first choice. During the build-up of the developing environment, however, I was frustrated due to the installation of scikit-learn package.
Quick tip: download the latest stable version (0.14a1) of scikit-learn and play with the sample code given in the source package.
Installation by pip (failed)
The first frustration might be caused by my stupidity.
I googled for the solution again and again, and found all the answers pointed to ``multiple versions of Python installed in the system.'' But I have only Python 2.7 in my Ubuntu!
What I had done was uninstall the scikit-learn and reinstall. Also I tried to install it from the source, but nothing changed.
Then I thought of something and tried to find some sample code on the scikit-learn page. It turned out that the module should be sklearn instead of scikits.learn... Orz
So what I had found was a sample code using old module names.
Using version 0.13.1 (failed)
I am not sure whether this is a bug. I could not run the example code (fa_recognition.py) located in the source package of version 0.13.1. When my scikit-learn modules were also the version 0.13.1. The error message was:
ImportError: cannot import name column_or_1d
and I found ``import sklearn.datasets'' would trigger this error.
I also tried to follow the traceback message given by the interpreter but only knew it was due to an importing of label.py. My skill on debugging couldn't bring me further.
Verion 0.14a1 (Succeeded)
Okay, I'd run out my approaches... I almost gave up, but then I thought of the possibility of using the latest version to solve the problem. So I downloaded the source of version 0.14a1 and installed it. Finally, I got the sample code run with expected outputs.
Face recognition example test
If you have downloaded the source package, you can find the example in the path of: YOUR_FOLDER/scikit-learn-0.14a1/examples/applications/face_recognition.py.
Frankly, I have no idea about the output yet, but I would like to post the text output of running face_recognition.py with the figures of result.
Text output
===================================================
Faces recognition example using eigenfaces and SVMs
===================================================
The dataset used in this example is a preprocessed excerpt of the
"Labeled Faces in the Wild", aka LFW_:
http://vis-www.cs.umass.edu/lfw/lfw-funneled.tgz (233MB)
.. _LFW: http://vis-www.cs.umass.edu/lfw/
Expected results for the top 5 most represented people in the dataset::
precision recall f1-score support
Gerhard_Schroeder 0.91 0.75 0.82 28
Donald_Rumsfeld 0.84 0.82 0.83 33
Tony_Blair 0.65 0.82 0.73 34
Colin_Powell 0.78 0.88 0.83 58
George_W_Bush 0.93 0.86 0.90 129
avg / total 0.86 0.84 0.85 282
2013-07-31 08:04:43,243 Downloading LFW metadata: http://vis-www.cs.umass.edu/lfw/pairsDevTrain.txt
2013-07-31 08:04:46,028 Downloading LFW metadata: http://vis-www.cs.umass.edu/lfw/pairsDevTest.txt
2013-07-31 08:04:46,740 Downloading LFW metadata: http://vis-www.cs.umass.edu/lfw/pairs.txt
2013-07-31 08:04:48,140 Downloading LFW data (~200MB): http://vis-www.cs.umass.edu/lfw/lfw-funneled.tgz
2013-07-31 08:11:24,620 Decompressing the data archive to /home/thk/scikit_learn_data/lfw_home/lfw_funneled
2013-07-31 08:11:33,822 Loading LFW people faces from /home/thk/scikit_learn_data/lfw_home
2013-07-31 08:11:33,981 Loading face #00001 / 01288
2013-07-31 08:11:36,218 Loading face #01001 / 01288
Total dataset size:
n_samples: 1288
n_features: 1850
n_classes: 7
Extracting the top 150 eigenfaces from 966 faces
done in 0.806s
Projecting the input data on the eigenfaces orthonormal basis
done in 0.065s
Fitting the classifier to the training set
done in 16.244s
Best estimator found by grid search:
SVC(C=1000.0, cache_size=200, class_weight=auto, coef0=0.0, degree=3,
gamma=0.001, kernel=rbf, max_iter=-1, probability=False,
random_state=None, shrinking=True, tol=0.001, verbose=False)
Predicting people's names on the test set
done in 0.049s
precision recall f1-score support
Ariel Sharon 0.67 0.78 0.72 18
Colin Powell 0.77 0.80 0.78 61
Donald Rumsfeld 0.71 0.76 0.73 29
George W Bush 0.90 0.89 0.89 134
Gerhard Schroeder 0.71 0.63 0.67 27
Hugo Chavez 0.93 0.58 0.72 24
Tony Blair 0.69 0.83 0.75 29
avg / total 0.81 0.80 0.80 322
[[ 14 2 1 1 0 0 0]
[ 3 49 1 3 0 1 4]
[ 1 3 22 2 0 0 1]
[ 2 6 4 119 1 0 2]
[ 1 1 1 4 17 0 3]
[ 0 3 1 0 5 14 1]
[ 0 0 1 3 1 0 24]]