Konda.eu

Tag Archives: opencv

No comments

Building OpenCV Stereo Vision - Getting Depth Images and 3D Point Cloud

At this point I'll assume entire stereo vision rig is setup and calibrated with calibration error small enough to get anything useful. If not, you can take a look how to calibrate or most common calibration mistakes for help with calibration.

Depth Image

Continue reading

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

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