Archive for the ‘programming’ Category
Combining OpenCV 2.x and Microsoft WPF [w/ code]
Hi,
Just a quicky about OpenCV and Windows Presentation Framework interoperability. It’s really easy with a simple Managed C++ wrapper. What I’ll show is how to transfer an OpenCV cv::Mat into WPF’s BitmapSource. Let’s see how it’s done.
Read the rest of this entry »
Image Recoloring using Gaussian Mixture Model and Expectation Maximization [OpenCV, w/Code]
Hi,
I’ll present a quick and simple implementation of image recoloring, in fact more like color transfer between images, using OpenCV in C++ environment. The basis of the algorithm is learning the source color distribution with a GMM using EM, and then applying changes to the target color distribution. It’s fairly easy to implement with OpenCV, as all the “tools” are built in.
I was inspired by Lior Shapira’s work that was presented in Eurographics 09 about image appearance manipulation, and a work about recoloring for the colorblind by Huang et al presented at ICASSP 09. Both works deal with color manipulation using Gaussian Mixture Models.
Let’s see how it’s done!
Read the rest of this entry »
Iterative Closest Point (ICP) for 2D curves with OpenCV [w/ code]
ICP – Iterative closest point, is a very trivial algorithm for matching object templates to noisy data. It’s also super easy to program, so it’s good material for a tutorial. The goal is to take a known set of points (usually defining a curve or object exterior) and register it, as good as possible, to a set of other points, usually a larger and noisy set in which we would like to find the object. The basic algorithm is described very briefly in wikipedia, but there are a ton of papers on the subject.
I’ll take you through the steps of programming it with OpenCV.
Read the rest of this entry »
Bust out your own graphcut based image segmentation with OpenCV [w/ code]
This is a tutorial on using Graph-Cuts and Gaussian-Mixture-Models for image segmentation with OpenCV in C++ environment.
Been wokring on my masters thesis for a while now, and the path of my work came across image segmentation. Naturally I became interested in Max-Flow Graph Cuts algorithms, being the “hottest fish in the fish-market” right now if the fish market was the image segmentation scene.
So I went looking for a CPP implementation of graphcut, only to find out that OpenCV already implemented it in v2.0 as part of their GrabCut impl. But I wanted to explore a bit, so I found this implementation by Olga Vexler, which is build upon Kolmogorov’s framework for max-flow algorithms. I was also inspired by Shai Bagon’s usage example of this implementation for Matlab.
Let’s jump in…
Read the rest of this entry »
Quick and Easy Head Pose Estimation with OpenCV [w/ code]
Just wanted to share a small thing I did with OpenCV – Head Pose Estimation (sometimes known as Gaze Direction Estimation). Many people try to achieve this and there are a ton of papers covering it, including a recent overview of almost all known methods.
I implemented a very quick & dirty solution based on OpenCV’s internal methods that produced surprising results (I expected it to fail), so I decided to share. It is based on 3D-2D point correspondence and then fitting of the points to the 3D model. OpenCV provides a magical method – solvePnP – that does this, given some calibration parameters that I completely disregarded.
Here’s how it’s done
Implementing PTAM: stereo, tracking and pose estimation for AR with OpenCV [w/ code]
Been working hard at a project for school the past month, implementing one of the more interesting works I’ve seen in the AR arena: Parallel Tracking and Mapping (PTAM) [PDF]. This is a work by George Klein [homepage] and David Murray from Oxford university, presented in ISMAR 2007.
When I first saw it on youtube [link] I immediately saw the immense potential – mobile markerless augmented reality. I thought I should get to know this work a bit more closely, so I chose to implement it as a part of advanced computer vision course, given by Dr. Lior Wolf [link] at TAU.
The work is very extensive, and clearly is a result of deep research in the field, so I set to achieve a few selected features: Stereo initialization, Tracking, and small map upkeeping. I chose not to implement relocalization and full map handling.
This post is kind of a tutorial for 3D reconstruction with OpenCV 2.0. I will show practical use of the functions in cvtriangulation.cpp, which are not documented and in fact incomplete. Furthermore I’ll show how to easily combine OpenCV and OpenGL for 3D augmentations, a thing which is only briefly described in the docs or online.
Here are the step I took and things I learned in the process of implementing the work.
Update: A nice patch by yazor fixes the video mismatching – thanks! and also a nice application by Zentium called “iKat” is doing some kick-ass mobile markerless augmented reality.
Read the rest of this entry »
iPhone OS 3.x Raw data of camera frames
It looks like it’s finally here – a way to grab the raw data of the camera frames on the iPhone OS 3.x.
Update: Apple officially supports this in iOS 4.x using AVFoundation, here’s sample code from Apple developer.
A gifted hacker named John DeWeese was nice enough to comment on a post from May 09′ with his method of hacking the APIs to get the frames. Though cumbersome, it looks like it should work, but I haven’t tried it yet. I promise to try it soon and share my results.
Way to go John!
Some code would be awesome…
Roy.
SmartHome – Embedded computing course project
Hi
In the past few weeks I have been working hard at a few projects for end-of-term at Uni. One of the projects is what I called “SmartHome”, for Embedded computing [link] course, is a home monitoring [link] application. In the course the students were given an LPC2148 arm7-MCU (NXP) based education board, implemented by Embedded Artists [link]. My partner Gil and I decided to work with ZigBee extension modules [link] to enable remote communication.
Here are the steps we took to bring this project to life.
Read the rest of this entry »
Recoloring via Histogram Matching with OpenCV [w/ code]
Hi
I wanted to do the simplest recoloring/color-transfer I could find – and the internet is just a bust. Nothing free, good and usable available online… So I implemented the simplest color transfer algorithm in the wolrd – Histogram Matching.
Here’s the implementation with OpenCV
Extending Justin Talbot’s GrabCut Impl [w/ code]
Justin Talbot has done a tremendous job implementing the GrabCut algorithm in C [link to paper, link to code]. I was missing though, the option to load ANY kind of file, not just PPMs and PGMs.
So I tweaked the code a bit to receive a filename and determine how to load it: use the internal P[P|G]M loaders, or offload the work to the OpenCV image loaders that take in many more type. If the OpenCV method is used, the IplImage is converted to the internal GrabCut code representation.
Image<Color>* load( std::string file_name )
{
if( file_name.find( ".pgm" ) != std::string::npos )
{
return loadFromPGM( file_name );
}
else if( file_name.find( ".ppm" ) != std::string::npos )
{
return loadFromPPM( file_name );
}
else
{
return loadOpenCV(file_name);
}
}
void fromImageMaskToIplImage(const Image<Real>* image, IplImage* ipli) {
for(int x=0;x<image->width();x++) {
for(int y=0;y<image->height();y++) {
//Color c = (*image)(x,y);
Real r = (*image)(x,y);
CvScalar s = cvScalarAll(0);
if(r == 0.0) {
s.val[0] = 255.0;
}
cvSet2D(ipli,ipli->height - y - 1,x,s);
}
}
}
Image<Color>* loadIplImage(IplImage* im) {
Image<Color>* image = new Image<Color>(im->width, im->height);
for(int x=0;x<im->width;x++) {
for(int y=0;y<im->height;y++) {
CvScalar v = cvGet2D(im,im->height-y-1,x);
Real R, G, B;
R = (Real)((unsigned char)v.val[2])/255.0f;
G = (Real)((unsigned char)v.val[1])/255.0f;
B = (Real)((unsigned char)v.val[0])/255.0f;
(*image)(x,y) = Color(R,G,B);
}
}
return image;
}
Image<Color>* loadOpenCV(std::string file_name) {
IplImage* im = cvLoadImage(file_name.c_str(),1);
Image<Color>* i = loadIplImage(im);
cvReleaseImage(&im);
return i;
}
Well, there’s nothing fancy here, but it does give you a fully working GrabCut implementation on top of OpenCV… so there’s the contribution.
GrabCutNS::Image<GrabCutNS::Color>* imageGC = GrabCutNS::loadIplImage(orig);
GrabCutNS::Image<GrabCutNS::Color>* maskGC = GrabCutNS::loadIplImage(mask);
GrabCutNS::GrabCut *grabCut = new GrabCutNS::GrabCut( imageGC );
grabCut->initializeWithMask(maskGC);
grabCut->fitGMMs();
//grabCut->refineOnce();
grabCut->refine();
IplImage* __GCtmp = cvCreateImage(cvSize(orig->width,orig->height),8,1);
GrabCutNS::fromImageMaskToIplImage(grabCut->getAlphaImage(),__GCtmp);
//cvShowImage("result",image);
cvShowImage("tmp",__GCtmp);
cvWaitKey(30);
I also added the GrabCutNS namespace, to differentiate the Image class from the rest of the code (that probably has an Image already).
Code is as usual available online in the SVN repo.
Enjoy!
Roy.


