Konda.eu

Blog

No comments

Most Common Mistakes when doing Stereo Calibration

While making my stereo rig, it took me 15 tries to make it right. It started to get really depressing, but every time I learned something new. Below are a few most common mistakes I made while taking calibration images for stereo vision.

Not enough images - when calculating projection matrices and distortions, the more images there are the better. Not enough images result in a bad projection matrix therefore worse results. There should be at least 10 images for calibration, but for just to be on the safe side make it 20 or 30. More than that might again corrupt your results.

Bad pattern coverage on the image - sample images should contain chessboard on about every position in the image. In all of the corners, sides, center and also under different angles (pitch, yaw and roll). Not having that kind of variety of images means bigger errors on parts of the images not covered.

Bad lighting - as everything in computer vision, good lighting is essential! Dark areas usually won't get calculated at all. That's one of the reasons Kinect uses IR light.

Low resolution - while taking calibration images, it's extremely important that the pattern is correctly and accurately detected. When going further away, squares get smaller consequently corners of the squares aren't touching any more as shown on the image bellow. The algorithm when searching for the points of interest can now choose between two different points, skyrocketing error which nobody wants.

Print that chessboard! - My first tries were taking images where pattern was displayed on a tablet. Trying to be environmental and all. The problem that occurred was the same as with the low resolution, only much worse. White areas on the screen were radiating that much light that black squares were starting to erode, causing the effect as shown on the image bellow.

calib_err

No comments

Building OpenCV Stereo Vision - Calibration

Once the hardware is set up, entire rig must be calibrated. Cheap cameras have a lot of distortion. Two major distortions are radial and tangential. Radial is usually noticed on the edge of the screen where image is slightly curved. Edges that should be perfectly straight are suddenly slightly bended. With tangential distortion the problem is somewhat similar, only that certain points on the image appear closer than their neighbors, even though they are not.

In order to overcome this problems cameras must be calibrated. Therefore, a series of images is taken with a well know pattern. OpenCV uses chessboard as shown below.

chessboard

Continue reading

No comments

Building OpenCV Stereo Vision - Setup

For my most recent project I decided to build Stereo Vision for depth detection. The idea is simple. Two cameras working together similar to human eyes and detecting depth in the image. There are a few nice practical usages such as 3D pictures or point clouds, measuring distance to a point on an image and many more.

I used two Logitech's S7500 cameras. Pretty old cameras supporting resolution of 640x480px for video capture, but were enough to build a basic setup. It is not completely necessary, that cameras are of the same model, but it is highly recommended for better results. Different lens distortion, quality etc. can affect calibration, resulting in larger errors.

Cameras

I duct taped both cameras on a piece of wood so that they were completely stable. The distance between camera lenses was approximately 7 cm, similar to the distance between human eyes. I additionally aligned camera heads so they were as parallel as possible.

At this point everything is ready for the last step before making depth maps - calibration.

No comments

Taming Bootstrap 3 - Columns Same Height

During my recent work on a web design layout with bootstrap, I came across a layout that required all bootstrap columns to be the same height. After some experimenting with various positions such as absolute inside relative etc. and none of them working as they should, I ended up using display: flex and wrapped it in a snippet as bellow.

@media (min-width: 992px) {
    .row-eq-height, .row-eq-height > div[class*='col-'] {
        display: -webkit-flex;
        display: flex;
        flex:1 1 auto;
    }
}

Usage example and demo are shown here:

<div class="container">
    <div class="row row-eq-height">
        <div class="col-sm-4 col-1" style="background: red">
            Some Text
        </div>
        <div class="col-sm-4 col2" style="background: green"></div>
        <div class="col-sm-4 col3" style="background: blue"></div>
    </div>
</div>
No comments

Measuring Decibels from Microphone

This year was my third year as a mentor at a summer computer camp. We all had lots of fun, the only problem was that the participants - mostly teenage kids at the beginning of the high school - were quite talkative. Loud. To solve this problem a colleague and I came up with a nice solution for the next year.

Continue reading

No comments

Playing Video from WebCam with OpenCV and C++

Cross platform video grabbing can sometimes be really painful. Another great thing about OpenCV is that it solves such problems for you with a couple of clean lines of code.

#include <iostream>
#include "opencv2/highgui/highgui.hpp"

using namespace std;
using namespace cv;

int main()
{
    VideoCapture cam(0);

    if (!cam.isOpened())
        return -1;

    cv::Mat frame;

    while (true)
    {
        cam.grab();
        cam.retrieve(frame);
        imshow("Cam:", frame);
        cv::waitKey(1);
    }

    return 0;
}
No comments

Install, compile and link OpenCV from Terminal on Linux

Almost all my development is done in Visual Studio. Currently the best IDE in my opinion, but such tools can quickly spoil you. After being thrown in front of a Linux with only a terminal and an OpenCV dependent program that needed to compile, it was a struggle, but I found the following line to compile everything:

g++ `pkg-config --cflags --libs opencv` source.cpp -o program

And in case you haven't got OpenCV yet installed, you can use simple apt-get command:

sudo apt-get install libopencv-dev
No comments

C++ - Optimizing away vtable with metaprogramming


Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wp-content/plugins/latex/latex.php on line 47

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wp-content/plugins/latex/latex.php on line 49

In every object oriented language class inheritance is a life saver when it comes to program architecture. A rather nasty side effect that comes with it is usually performance degradation. And in C++ that penalty can be quite noticeable. When working with virtual methods in derived classes compiler generates vtable (Virtual Method Table), where address for each overridden method is specified. Vtable is then used every time virtual method is called to lookup that address, jump to it and execute code at that location. That penalty can quickly increase execution time by \(\). There is a neat trick that allows us to resolve those addresses compile-time allowing compiler to optimize vtable away using metaprogramming.

Continue reading

No comments

C++ - Unicode Strings! Say Goodbye to std::string

During my years of programming in C++, the biggest pain were probably strings. There is no simple standard cross platform way for Unicode strings. std::string class by itself is also lacking a lot of methods for every day work. Comparing it to C#, Java or any other language is almost useless. Features as starts withends withto lower, to upper, trim and similar are all missing. It has ==, while Java doesn't. Yes, all of the functions above can be easily written with templates but it adds an extra load of work and maintenance, which we all try to avoid.

After a couple of years I finally decided to try ICU - International Components for Unicode. It's a C++ library for Unicode strings. It weights roughly 20MB when shipped with executable, but it's totally worth it. Linux, Apple, Google Chrome and other mayor companies or products use it. All of the above functions are provided and a couple more, all mayor code tables are supported, file access is with already familiar C like interface and as a bonus it's fully integrated with C++ streams.

icu::UnicodeString str = L"Hi ICU with öäüšćž!";
str = str.toLower();
str = str.append(" Foo!   ").trim();

cout << str << endl;

I urge you, give ICU a try!