Friday, December 19, 2008

iPhone camera access - an alternative way with official SDK

iPhone developers are looking for an alternative way to use camera with official SDK since Apple does not release direct access to the built-in camera and just provide an interface to capture an image. One way is to customize UIImagePickerView to get full screen video preview.

There is a discussion at

http://blog.airsource.co.uk/index.php/2008/11/11/views-of-uiimagepickercontroller



A video showing the implementation : 




Building OpenCV on Windows Mobile 6


Open Computer Vision Library (OpenCV) is a computer vision & image processing library widely used in computer vision community. It supports MS Windows, Apple MAC OS X, and linux systems.

Recently, I need to port my marker tracking module on Windows Mobile 6 (WM6) platform, and thus I have to build OpenCV on WM6. I searched articles on the web, but there are not many posts related to this issue. So, I decided to do it on my own. 
Fortunately, OpenCV is written in C language and it is platform-independent except highgui and cvcam. Well, what I need is only cv and cxcore library which are really C codes. 

To build OpenCV on Windows Mobile, we need to modify some of codes. 


1. cxtypes.h

(1) cvRound( double value ) : Leave the code below and comment the others in the function as follows. 


 
//--------------------------------------
  Cv64suf temp;
  temp.f = value + 6755399441055744.0;
  return (int)temp.u;
//--------------------------------------


2. cxerror.cpp : 

An error occurs because  TLS_OUT_OF_INDEXES is not defined. It is defined in the desktop version of windows.h, but not in Windows Mobile. So, I just  borrowed the definition from desktop version of windows.h. 

//--------------------------------------------
// Before

// Error occurs here. 
#if defined WIN32 || defined WIN64
    static DWORD g_TlsIndex = TLS_OUT_OF_INDEXES; 
#else
    static pthread_key_t g_TlsIndex;
#endif

//-------------------------------



//--------------------------------------------
//
After

#define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF) 
   static DWORD g_TlsIndex = TLS_OUT_OF_INDEXES;

//----------------------------------------------


3. cxswitcher.cpp 

Many errors occur in this file. Almost of them seem to be related to IPP. I just commented out the functions that caused errors and left their blank body.  

4. cxmisc.h

Errors come here since the build environment is not defined. Including malloc.h is enough to avoid compile errors. 

//---------------------------------------------------
//
Before

/* get alloca declaration */
#ifdef __GNUC__
#undef alloca
    #define alloca __builtin_alloca
#elif defined WIN32 || defined WIN64
#if defined _MSC_VER || defined __BORLANDC__
    #include "malloc.h" 
#endif
#elif defined HAVE_ALLOCA_H
    #include "alloca.h"
#elif defined HAVE_ALLOCA
    #include "stdlib.h"
#elif
    #error
#endif

//---------------------------------------------------


//---------------------------------------------------
//
After

#include "malloc.h"

//---------------------------------------------------

5. WinMain(..) function

There is a WinMain function for building library in OpenCV source code. just comment it out. We do not need it any more since we already have one in the Windows Mobile project. 


After you modify codes I showed above, create a Windows Mobile library project in your Visual Studio and build OpenCV. The change I made in the source code is not carefully examined what problems they will cause. However, there is no problem until now in my case. I showed a screenshot of a simple OpenCV application executed on the WM6 emulator. Of course, it works well on the device.