Pages - Menu

Monday, January 25, 2010

Optitrack Sample Code

Here is a sample code and some details. Follow the steps in the images below to configure the project. Download the Project folder from the link at the bottom. 


Open a new project and enter the code. Right click on the project and open properties. Now click Linker and select Input. Type optitrackuuid.lib in to Additional Dependances.


Important notes:




Component Object Model (COM)
It is a binary-interface. It is used to enable inter-process communication and dynamic object creation.


ATL  [library/Framework]
The Active Template Library (ATL) is a set of template-based C++ classes that simplify the programming of Component Object Model (COM) objects.


Com provides a method for sharing binary code across different applications and languages.With COM, A component can be created which communicates with programs that are written in any software language. Using ATL, it is possible to add “parts” to the component easily.


Let us assume that a camera is initialized as COM object. By making use of ATL, frame count (an integer type) is defined as a member of this camera. Since the camera is a COM object, there is an interface to access camera and obtain the frame count via a C++ program or a java program alike. And the programs can access and pass these “members” to each other. Thus in COM the Components, Objects, classes and its members remain unaffected by the language used.


For more interesting Explanation:
http://www.codeproject.com/KB/COM/comintro.aspx 


Sample Code:


//______________________________________________________________________________________
// Marker Detection Demo Program
// Author: Bharath Prabhuswamy
//______________________________________________________________________________________
//______________________________________________________________________________________
#pragma once

#define WIN32_LEAN_AND_MEAN 
#define _USE_MATH_DEFINES   

#include <conio.h>      

#include <objbase.h>
#include <atlbase.h>
#include "optitrack.h"
#import  "optitrack.tlb"

int _tmain(int argc, _TCHAR* argv[])
{
 printf("**  Marker Detection Demo Program  --------------------------------------------\n");
 printf("**  Author: Bharath Prabhuswamy    --------------------------------------------\n\n");

 //Initialize COM__________________________________________________
 CoInitialize(NULL);

 //Initialize Optitrack COM Objects________________________________
 CComPtr<inpcameracollection> cameraCollection;
 CComPtr<inpcamera>           camera;
 CComPtr<inpcameraframe>   frame;
 
 //Create uninitialized object of the class associated CLSID_______
    cameraCollection.CoCreateInstance(CLSID_NPCameraCollection);

 //Enumerate (Identify) Available Cameras__________________________
 cameraCollection->Enum();

 long cameraCount  = 0;
 int  frameCounter = 0;

 //Determine Available Cameras_____________________________________
    cameraCollection->get_Count(&cameraCount);
 
 
 //Open the camera if any detected_________________________________
 if(cameraCount>0)
 {
  cameraCollection->Item(0, &camera);
  {
   //Open camera 0 (i.e. first camera), and set various parameters___
   cameraCollection->Item(0, &camera);

   //Set Greyscale Mode_____________________________________________
   camera->SetOption(NP_OPTION_VIDEO_TYPE , (CComVariant) 1 );

   //Set to discard every other frame out of 120 frames
   //(i.e. 60 Frames/Second)_________________________________________
   camera->SetOption(NP_OPTION_FRAME_DECIMATION  , (CComVariant) 1 );

   //Set User defined Threshold_______________________________________
   camera->SetOption(NP_OPTION_THRESHOLD  ,  (CComVariant) 253);

   //Set User defined Intensity_______________________________________
   camera->SetOption(NP_OPTION_INTENSITY  ,  (CComVariant) 15);

   //Set User defined Exposure________________________________________
   camera->SetOption(NP_OPTION_EXPOSURE  ,  (CComVariant) 201);

   //Set User defined Ranking options_________________________________
   camera->SetOption(NP_OPTION_OBJECT_MASS_WEIGHT  ,  (CComVariant) 0);
   camera->SetOption(NP_OPTION_OBJECT_RATIO_WEIGHT  ,  (CComVariant) 2);
   camera->SetOption(NP_OPTION_PROXIMITY_WEIGHT  ,  (CComVariant) 0);
   camera->SetOption(NP_OPTION_STATIC_COUNT_WEIGHT  ,  (CComVariant) 0);
   camera->SetOption(NP_OPTION_SCREEN_CENTER_WEIGHT  ,  (CComVariant) 0);
   camera->SetOption(NP_OPTION_LAST_OBJECT_TRACKED_WEIGHT  ,  (CComVariant) 10);

   camera->Open();
   camera->Start();
   {
       while(!_kbhit())
       {
        camera->GetFrame(0, &frame);

     if(frame!=0)
     {
      //Increment Frame Counter_____________________________________
      frameCounter++;

      //Process Every Frame_________________________________________
      if((frameCounter%1==0))
      {
       long Objcount = 0;
       long rank;
       CComVariant X, Y, Area;
       
       //Obtain Objects from frame of camera________________________
       frame->get_Count(&Objcount);
   
       //Get data of all objects____________________________________
       for (int i = 0; i < Objcount; i++)          
       {
        CComPtr<inpobject> object;
        frame->Item(i,&object);
        object->Transform(camera);

        object->get_Rank(&rank);
        
        //Store data of object with first rank______________________
        if(rank == 1)
        {
         object->get_X(&X);
         object->get_Y(&Y);
         object->get_Area(&Area);        
        }
       }
       //Print the values of the object_____________________________    
       printf("X value is =%f/tY value is =%f/tArea is =%f\n\n",X.dblVal, Y.dblVal, 
Area.dblVal);
      }
      frame->Free();
      frame.Release();
     }
       }   
            }
   camera->Stop();
   camera->Close();
  }
  camera.Release();
 }

 //Clean-up COM Objects____________________________________________
 cameraCollection.Release();

 //Uninitialize COM________________________________________________
 CoUninitialize();

 printf("Application Exit.\n");
 return 0;
}
Downloads:
Download Project folder with Source 2.89Mb


Images:





Setting up VC++ for Optitrack programs

For developing custom programs, Natural point provides its libraries to which have to linked in your projects to make use of Optitrack cameras.

Download OptiTrack SDK for V100R2, V100, C120, FLEX:3 Cameras - Official Release - Version 1.3.035 (.exe 2.5 MB) from the link below and Install.

After installation, a folder containing dlls, drivers, libraries and documentation file will be created in Program files

Now include the directories of the optitrack headers and optitrack libraries into the Visual Studio.


Before opening any projects, open Tools from the menu bar and select Options.
In the Options window select VC++ Directories.Open  Show the Directories for: and select Include files.

Add the path where the Optitrack include files [optitrack.h & optitrack.tlb] are present.
Ex: C:\Program Files\NaturalPoint\Optitrack\inc

Similarly select Library files from Show the Directories for: option. Now add the path where the Optitrack library [optitrackuuid.lib] is present.
Ex: C:\Program Files\NaturalPoint\Optitrack\lib\i386

Click on OK to save the changes

Now all you have to do is create a new cpp project and add the following headers to your program -
#include "optitrack.h"
#import  "optitrack.tlb"

Note: It is also necessary to include atlbase.h & objbase.h to make use of COM.


Images:









Optitrack FLEX C120 Infrared Camera

I had the opportunity to use this camera for rigid body tracking. 
Optitrack cameras are generally used for motion capture (tracking). This is an IR camera with 120Hz frame rate. Development of custom programs can be accelerated by starting off with the SDK provided by Natural point. A well explained Documentation is also available along with the SDK.

The sample applications* include the complete GUI and display window for the captured images.
[*refers to Optitrack SDK C++ VC8 Sample from the link below.]


I used the non-reflective markers (7/16th of an inch) for my applications.


Note: This Product Has Been Discontinued.


Links:





Images:




Saturday, January 23, 2010

Click! Download Buttons

Download buttons for linking files.. I will embed them to my blog..:D


Objects:

Click by ~bharathp666 on deviantART

Friday, January 15, 2010

Android Application Icons Set

Could not find the android icons? Download Here!!!
[Some of them are not exact copy of the originals.]


Note: For Non-Commercial use only!!


Link:
Download Android Applications Icons [PNGs only] 1.81 Mb


Objects:

Android Application Icons Set by ~bharathp666 on deviantART



Images:









Sunday, January 10, 2010

Syntax highlighter by Alex Gorbatchev

I was looking forward to put some codes here. This is when I came across this cool tool. Syntax Highlighter is an open source code highlighter developed in JavaScript by Alex Gorbatchev. It highlights codes written in various lanuages like C++, C#, Java, Javascript, SQL, XML and many more. It also has 6 different themes for the background. Great stuff Alex!!

Download the Syntax Highlighter and upload the libraries in some web space.  Link those libraries into the HTML code of your blog. Or you can also use the online version where the libraries are already present online. The demo below uses the online version.

I was looking for some support on how to use it, and ended up with something funny like this picture here. Well, they were using Syntax Highlighter to show 'how to use Syntax Highlighter'.
Anyways visit the site, download codes or use the online version.

Links:

Steps:
Copy the HTML codes below:


<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'></script>
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>




Open Blogger Dashboard, open Layout, in that select Edit HTML
Paste the above HTML codes just below
<head>
tag
Now save the template and try a new post.
Type these codes in HTML


<pre name="code" class="brush: cpp">
while(foo==1){
int bar==0;

printf("Welcome to the foo-bar methodology of algorithms !! ");
}
</pre>



And voilà! You have the Syntax Highlighter showing the code in a clean format as show below
while(foo==1){
int bar==0;
printf("Welcome to the foo-bar methodology of algorithms !! ");
}




Images:



Saturday, January 9, 2010

IEEE member benefits

I've been member of IEEE for 2 years and continuing. I've been treated to lot of benefits. The Spectrum magazine is a great monthly update. But events that are supported by IEEE are something else. My college [B.M.S College of Engineering] has official access to all IEEE papers! And best of all is Under-Grads like me, get access to Original Microsoft softwares free of cost!! Now thats where I got my Windows 7 RC and Visual Studio!
Join IEEE and reap the benefits ! Get acquainted to the world of technology.
Hit that button on the right!!!!


Links:
www.ieee.org
http://www.ieee.org/web/membership/join/join.html
http://www.ieee.org/web/membership/students/branchresources/microsoftofferstudents.html


http://spectrum.ieee.org/

Logitech QuickCam Pro 9000: Support

If you are facing any problems, the best hope will be the Discussion forums. The quickcamteam has an excellent forum and any problems regarding Logitech QuickCams are addressed here. (For other Logitech Webcams you can visit Logitech Support forums).
You can also post them as comments here in my Blog, I'll try to solve them as much as possible.


Links:
http://www.quickcamteam.net/
http://forums.quickcamteam.net/


http://forums.logitech.com/


Images:


Logitech QuickCam Pro 9000: Driver Installation

Here are the details of installing libwebcamdrivers. If you want save this for reading it later, download the PDF from the link below.


Download the .PDF version of this post: Logitech WebCams [PDF] 126kb



Logitech QuickCam Pro 9000

Visit the page below to find various versions in QuickCam Pro 9000-

libwebcam Homepage:

Installing the libwebcam drivers:



libwebcam
      libwebcam provides the following core features:
§  Enumeration of all cameras available in the system.
§  Provide detailed information about the detected devices and their controls.
§  Wrapper for the V4L2 frame format enumeration.
§  Convenient access to device controls.
Support for configuring the Linux UVC driver's dynamic controls (extension unit controls).
In addition, the interface is prepared to handle device events ranging from newly detected cameras over control value changes to device button events. It is easy to add new features without breaking application compatibility and the addition of new controls or events is straightforward.

uvcdynctrl
The source package also contains uvcdynctrl and a udev script that adds some extra controls to Logitech UVC models.

Refer the discussion here:

Installing libwebcam 

user@pc:~$ sudo apt-get install build-essential
It installs all the necessary files to build a program.

user@pc:~$ sudo apt-get install cmake
Cmake is a development tool through which programs can be built.

user@pc:~$ sudo apt-get install subversion mercurial libxml2-dev gengetopt
Subversion and mercurial are software maintenance facilities.
libxml2 and gengeopt are libwemcam dependencies.

user@pc:~$ svn http://svn.quickcamteam.net/svn/qct/webcam-tools/trunk libwebcam
It creates a folder named libwebcam and downloads all the files into it.

Get uvcvideo (and all other linuxtv.org drivers):
user@pc:~$ hg clone http://linuxtv.org/hg/v4l-dvb v4l-dvb

Copy
uvcvideo.h header to libwebcam folder:
user@pc:~$ cp v4l-dvb/linux/drivers/media/video/uvc/uvcvideo.h libwebcam/Common/include/.
  
Open uvcvideo.h in an editor and patch it:
user@pc:~$ nano libwebcam/Common/include/uvcvideo.h
or
user@pc:~$ gedit libwebcam/Common/include/uvcvideo.h
(Nano is a command-line editor and Gedit is an editor with GUI. Use any to change the code.)

Change the code from
__u8 __user *data;
to
__u8 *data;
in the structure uvc_xu_control

Code:
struct uvc_xu_control {
    __u8 unit;
    __u8 selector;
    __u16 size;
    __u8 *data;
};
 


Build and install libwebcam:

user@pc:~$ cd libwebcam
user@pc:~$ mkdir build
user@pc:~$ cd build
user@pc:~$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr
user@pc:~$ make
user@pc:~$ sudo make install


Installing guvcview
Visit the site below for more details:

Edit the packages source list:
user@pc:~$ sudo gedit etc/apt/sources.list

Add the following lines to the file:
deb http://ppa.launchpad.net/pj-assis/ppa/ubuntu karmic main 
deb-src http://ppa.launchpad.net/pj-assis/ppa/ubuntu karmic main


Note: For Ubuntu 9.04 (Jaunty) or Ubuntu 8.10 (Intrepid) replace karmic by jaunty or intrepid from the above commands.
Example:
deb http://ppa.launchpad.net/pj-assis/ppa/ubuntu jaunty main 
deb-src http://ppa.launchpad.net/pj-assis/ppa/ubuntu jaunty m
ain


Now add the ppa key to the system, by issuing the following commands:
user@pc:~$ gpg --keyserver keyserver.ubuntu.com --recv 0x9750A93F69FAF7DA 
user@pc:~$ gpg --export --armor 0x9750A93F69FAF7DA |sudo apt-key add -

You should now be able to install guvcview with aptitude
user@pc:~$ sudo apt-get install guvcview

This completes installation of guvcview.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  If you are interested in building the code or using the source for other purposes, use the commands below-

To get source code of guvcview:
user@pc:~$ svn checkout http://svn.berlios.de/svnroot/repos/guvcview/trunk guvcview
It creates a folder named guvcview and downloads all the files into it.

Refer: