Sunday, December 4, 2011

Master-Thesis Template

Recently some of friends started to work on their theses and why reinvent a new Word Template every time?
So today, I finally found the time to strip down my master thesis word document and made it a word template.

I used and created it with Word 2010.

It has:
* Automatic lists for figures, tables (use stylesheets)
* Automatic table of contents (use stylesheets)
* Automatic page numbering (small latin for lists and ToC; arabic for text; big latin for the appendix)
* Automatic title of the current chapter on each text page.

You need:
* Something to write about
* Know how to use style sheets in word
* Somebody who reads your final text for mistakes
* and at last a covering page

Feel free to use it and don't waste your time creating yet another word thesis template.
And also feel free to modify and extend it.

The link to the template again.

Thursday, November 10, 2011

Swissranger 4000 and OpenCV and Point Cloud Library

I am back on working with Depth Cameras and hand gesture recognition - now we are using a Swissranger SR4000 - a TOF camera - instead a Kinect. Here is demo code to get the camera data to OpenCV as well as Point Cloud Library.
/**
* Demo program for the SR4k that shows the output (DepthImage and PCL) and can export these as images.
* Use SPACE to take a picture and ESC for end.
 * @author Dennis Guse
 */
#include 
#include 
#include 
#include 

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"

//SR4k
#include "libMesaSR.h"
#include "definesSR.h"

#include "pcl/point_cloud.h"
#include "pcl/point_types.h"
#include "pcl/visualization/cloud_viewer.h"

using namespace cv;
using namespace std;
using namespace pcl;

#define SR_ROWS 176
#define SR_COLS 144
/**
 * Takes a picture with the SR4k and returns the depthimage as well as the point cloud!
 */
cv::Mat takePicture(SRCAM srCam, pcl::PointCloud::Ptr cloud) {
 SR_Acquire(srCam);
 cv::Mat depthImage(SR_ROWS, SR_COLS, SR_CV_PIXELTYPE, (unsigned short*)SR_GetImage(srCam, 0)); //0:DepthImage; 1:Amplitude; 2:ConfidenceMap

 float x [SR_ROWS * SR_COLS];
 float y [SR_ROWS * SR_COLS];
 float z [SR_ROWS * SR_COLS];
 SR_CoordTrfFlt(srCam, x, y, z, sizeof(float), sizeof(float), sizeof(float));

 for(int i=0; i<SR_ROWS * SR_COLS; i++) {
   point.x=x[i];
   point.y=y[i];
   point.z=z[i];
   point->points.push_back(point);
 }
 return depthImage;
}

int main(int argc, char **argv) {
 SRCAM srCam;
 SR_OpenETH(&srCam, SR_IP_ADDR); //Add error handling
 SR_SetMode(srCam, AM_COR_FIX_PTRN|AM_CONV_GRAY|AM_DENOISE_ANF|AM_CONF_MAP);

 pcl::visualization::CloudViewer viewer ("PCLViewer");
 while(true) {
  pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
  cv::Mat depthImage = takePicture(srCam, cloud);
  cv::imshow("Depth", depthIamge);

  viewer.showCloud(cloud, "Cloud");

  int key = waitKey(1);
  if (key == KEY_ESC) break;
  if (key != -1) saveDepthImageAndCloud(depthImage, cloud);
 }
}

Tuesday, September 13, 2011

Lenovo X60 and Ericcson F5521gw

My old Lenovo X60 (wwan ready: antenna an sim slot available) uses the current state of the art UMTS (mini pci express) card from Ericcson. The card orignally belongs to an Lenovo W520 - FRU is 60Y3279.

!I am using the original BIOS (no zender!)

Basically:
* Download drivers for the card from Lenovo
* Extract drivers (the .exe complains that my X60 is not supported) using InstallShield tools
* Cover pin 20 on the card with scotch tape. (Drawback: card cannot be turned off)
* Plugin the card (I am using only the main antenna)

Hint:
* Even with pin 20 enabled (no scotch) my notebook booted without error 180X and windows showed it in the device manager - but cannot be turned on!
* Fn+F5 (Access Connection) does not show the card, but the connection can be configured.
* Access Connection can turn the card off (probably via AT commands)

PIN 20: Not my image; credits go to the unknown creator.

Any question: Leave a comment with your mail-addr.

PS: In comparison to WiFi tethering with my Palm Pre: the card is awesome fast! (using O2 max. 3.6 Mbit/s)

Update:
Similar guide for Dell and a WWAN

Extract drivers from encrypted install shield archives

Image of PIN 20

PS: If you need something, just send me an email.

Friday, February 4, 2011

Matlab: Progressbar for arrayfun

If you use arrayfun on large arrays with really slow functions it is annoying to wait without feedback how long it can take - so a progressbar (in matlab waitbar) would be nice. One problem is that arrayfun provides no information about the status - there are no callback handlers.
What could be done instead.
Simply write function for arrayfun as inner function of the function which calls arrayfun. In the calling function
you define two variables, one for the number of items and one for the current solved items (starts with 0 and gets updated). In the inner function the work is done and the counter increment, which is visible in the inner function, because it is an inner function. At last update the waitbar.
Here is how it can look:
function doArrayFunWithProgressBar()
  data = magic(35);
  WAITBAR = waitbar(0, 'Work in progress');
  PROGRESS_COUNTER = 0;
  PROGRESS_MAX = sum(size(data));

  data = arrayfun(@(item)innerFun(item), data);

  close(WAITBAR);

  function result= innerFun(item) 
    %TODO Do the work!
    pause(1);

    PROGRESS_COUNTER = PROGRESS_COUNTER + 1;
    waitbar(PROGRESS_COUNTER / PROGRESS_MAX);
  end
end

Thursday, January 27, 2011

Matlab: if-statement in anonymous functions

UPDATE: The performance penalty is massive - MATLAB fails to optimize the code if anonymous functions or function handles are used. I got factor 20... But it works ;)

Today, I needed to write a function in Matlab as accessor to a matrix. I have a matrix which contain mulitple datastreams - one per row. The columns dimension is the time.
Because I don't want to change the functions, which evaluate only a subset of provided streams, and I don't want to copy and modify the matrix for every combination, I started to think about an accessor function.
Furthermore the function should reveal the dimensions of the (not existing) data matrix.

I ended up with anonymous functions, because these allow to access variables outside the anonymous function definition like:
a=2
b=2
fun=@(x)(a*x+b)
The advantage is that fun can use a and b, but the caller doesn't necessarily know that they exist and are used by fun.

With this knowledge the implementation of providing the correct data was straight forward. The next problem was, that in anonymous function you can't use the if-statement. That's pretty messy.
%%Artificial if for use in anonymous functions
%TRUE and FALSE are function handles.
function RESULT = iff(CONDITION,TRUE,FALSE)
  if CONDITION
    RESULT = TRUE();
  else
    RESULT = FALSE();
  end
end

The function that creates the function handles of the accessor function:
function HANDLE = recordHandle(COLUMN, ROWS)
  HANDLE = @(row, column) (...
    iff(nargin == 2, @()COLUMN(ROWS(row), column), @()[size(COLUMN, 2), size(ROWS, 1)])...
  );
end