sexta-feira, 15 de janeiro de 2010

Panoramic vision with a webcam

panoramic

Yesterday I’ve continued my experiments with openCV, this is a small demo that creates a panoramic vision using a simple webcam. It works best if the camera if the camera is attach to some support and moved using only rotation.

This demo takes advantage of the functions explained in the previous post but presents the new camera frames in an approximated position using the average displacement of the common points of the current and previous frames.

 

An interesting blog with useful function for OpenCV is this one: http://blog.weisu.org/search/label/OpenCV

quinta-feira, 14 de janeiro de 2010

Finding common points in two consecutive frames or stereo vision.

image

This was a little test program to understand how to work with the flow functions from OpenCV.

This example is based on the lkdemo demo from OpenCV.

In the first image I detect the most important points from the image such as corners using the cvGoodFeaturesToTrack function.

In the second image the same points were tracked using the cvCalcOpticalFlowPyrLK function.

terça-feira, 5 de janeiro de 2010

OpenCV and OpenFrameworks integration

Everyone that has used OpenFramewoks knows that there is an add-on that implements some functions from the OpenCV library. Most of these functions include basic image processing, blob tracking and face recognition. But what about the rest of the library? What if I want to use a Corner Detection function from OpenCv and still display the result in OpenFrameworks?

Bellow there is a simple code to use ofImage, ofxCvGrayscaleImage and ofxCvColorImage from OpenFrameworks and use them with OpenCV functions such as cvPreCornerDetect or cvDilate.

Using the OpenCV example in OpenFrameworks, extra declarations in testApp.h:

ofImage                    loader;
ofxCvGrayscaleImage cornersImg;
ofxCvColorImage colorImg;

in testApp.cpp these are the setup and draw functions.

void testApp::setup(){
loader.loadImage("t01-esq.png"); //load image
colorImg.allocate( loader.width,loader.height);
cornersImg.allocate( loader.width,loader.height);
colorImg.setFromPixels(loader.getPixels(), loader.width,loader.height);
//one channel 8bits values between 0 and 255
IplImage *gray = cvCreateImage(cvSize(loader.width,loader.height), IPL_DEPTH_8U, 1);
//one channel 32bits values between 0.0 and 1.0
IplImage *corners = cvCreateImage(cvSize(loader.width,loader.height), IPL_DEPTH_32F, 1);
IplImage *dilatedCorners = cvCreateImage(cvSize(loader.width,loader.height), IPL_DEPTH_8U, 1);
//convert to grayScale
cvCvtColor(colorImg.getCvImage(), gray, CV_BGR2GRAY);
cvPreCornerDetect( gray, corners, 7 );
cvDilate(corners,corners,0,1);

//convert from float do unsigned int by multiplying every falue by 255
cvConvertScale( corners, dilatedCorners, 255 );
cornersImg = dilatedCorners;
}

void testApp::draw(){
colorImg.draw(20,20);
cornersImg.draw( colorImg.width + 40, 20 );
}

the final result is the following application:

corners

Note that to convert an ofxCvColorImage to IPLImage we use setFromPixels, to convert an IPLImage to grayscale or color we use cvCvtColor, and to convert the type of the image from IPL_DEPTH_8U to IPL_DEPTH_32F and vice-versa we use cvConvertScale. To convert from IPLImage to ofxCvColorImage the image must be in the IPL_DEPTH_8U format with 3 channels, and just use “=”.

Some OpenCv functions require that the image to be in 32 bit float format. For further information read the OpenCV reference. There is no need to include additional files, OpenFrameworks already includes the OpenCV headers.

terça-feira, 15 de dezembro de 2009

Stereo Image Displacement

Image1

Today I constructed a small application to calculate the distance at which the objects are from the two stereo cameras. The image in the bottom left shows the nearer object in lighter colours and the far objects in darker tones. There are some problems especially in blank areas, where there are no big references to create the image (see red areas).

To calculate this image, for each pixel on the top left image I calculated the displacement of that point in the right image. The displacement is inversely proportional to the distance.

quinta-feira, 19 de novembro de 2009

Measuring the distance of an object

distance

This was a small demo that I did in Processing 1.0 to test stereo vision.

I took two pictures with a webcam. The second picture was taken 7 cm  (b) to the left of the first. In this demo, to measure the distance of a point I pick the same point in each picture. The distance is measured using triangulation. There is a linear relation between the displacement (H) in pixels ( green line in the door locker ), and the distance (Z).

H=b/Z

This only happens when the two images are taken by two cameras that are side by side on the some plane.

segunda-feira, 16 de novembro de 2009

OpenCV the Computer Vision Library

Great library, but it is very hard to make it work on Visual Studio 2009. There is no default .lib for VS so you have to make them yourself.

These are the instructions from the file:

OpenCV-2.0.0a-win32.Readme.Please.txt

1. Download CMake from http://www.cmake.org/cmake/resources/software.html
   and install it.

2. Run CMake GUI tool and configure OpenCV there:
   2.1. select C:\OpenCV2.0 (or the installation directory you chose)
        as the source directory;
   2.2. choose some other directory name for the generated project files, e.g.
        C:\OpenCV2.0\vs2008, or D:\Work\OpenCV_MinGW etc.
   2.3. press Configure button, select your preferrable build environment
   2.4. adjust any options at your choice
   2.5. press Configure again, then press Generate.
3a. In the case of Visual Studio or any other IDE, open the generated
   solution/workspace/project ..., e.g. C:\OpenCV2.0\vs2008\OpenCV.sln,
   build it in Release and Debug configurations

3b. In the case of command-line Makefiles, enter the destination directory
    and type "make" (or "nmake" etc.)
4. Add the output directories to the system path, e.g.:
   C:\OpenCV2.0\vs2008\bin\Debug;C:\OpenCV2.0\vs2008\bin\Release:%PATH%
   It is safe to add both directories, since the Debug
   OpenCV DLLs have the "d" suffix, which the Release DLLs do not have.
5. Optionally, add C:\OpenCV2.0\include\opencv to the list of
   include directories in your IDE settings,
   and the output library directories
   (e.g. C:\OpenCV2.0\vs2008\lib\{Debug,Release})
   to the list of library paths.

One afternoon was lost with this, It would just be better if they gave all the compiled stuff from the beggining…

sexta-feira, 13 de novembro de 2009

Tema da tese definido

“Building interactive spatial and temporal models
using multimodal data”

 

Abstract

The construction of virtual world models is an important step in several applications from simulations to virtual reality. These threedimensional worlds are usually constructed oine from scratch or using large datasets of data extracted from satellites. Once they are constructed they are usually static or hard to alter automatically. What is proposed in this thesis is a  method to create methods that would take advantage of several types of low-cost sensors and computer vision to quickly create and update virtual models. These virtual models will have live feeds from the sensors and from images and videos. The resulting model can be consulted in terms of space and time, turning on and o several layers of information. These models can  then be used in several scenarios such as retrieving information from a physical space, creating simulations or creating augmented reality scenes. One of the main ideas proposed is the fact that changes in the virtual model can be reflected back to the images and videos that helped in its construction. This reconstruction of reality can have several applications to visualize the results of environmental simulations such as pollution or disaster simulations, showing the a ected areas in real life images. Additionally it can be useful to superimpose virtual objects to be used in augmented reality, turning the room where the user is into a completely di erent scenario. The construction of the models involves the study of several image processing algorithms and techniques. Additionally, to support the fast creation, visualization and interaction with the models several tools will have to be developed. The interaction should explore new paradigms di erent from the mouse and keyboard. Essentially it should take advantage of the computer vision knowledge learnt in the construction of the models. This document addresses the problems involved in this area, presents related work, preliminary solutions and a work plan for the thesis.