DENKTECH
| Home | About | Products | Tools | Downloads | Contacts |
Products > Software > libdtcam

libdtcam

This package is developed for easy integration of DTI interferometers into user software. It contains C control and image capture library, Python and Matlab bindings. All modules are available in source code.

C library

Open-source, platform independent, socket based image capture and control C library. It has simple functions, and can be easy integrated into new or existing software.

Functions

perform_http_request ( addr, port, uri, buf, size, err_buf, err_size )
   This function creates socket and sends HTTP request to web server, waits response and stores it into buffer.

Parameters:
   addr - server IP address
   port - server port
   uri - resource name
   buf - response from server
   size - buffer size
   err_buf - buffer for error message
   err_size - maximal size of error message

Return values:
   response size - if >= 0
   error code - if < 0


process_http_response ( buf, size, type, err_buf, err_size )
   Parse response from HTTP server.

Parameters:
   buf - response from server
   size - buffer size
   type - content type
   err_buf - buffer for error message
   err_size - maximal size of error message

Return values:
   content size - if >= 0
   error code - if < 0


extract_pgm ( buf, size, width, height, bpp, err_buf, err_size )
   Extract binary array form PGM image format.

Parameters:
   buf - PGM image
   size - buffer size
   width - image width
   height - image height
   bpp - image digitization (bits per pixel)
   err_buf - buffer for error message
   err_size - maximal size of error message

Return values:
   image size - if >= 0
   error code - if < 0

Usage

Image capture example
#include "dtcam.h"
...
result = perform_http_request(
    inet_addr("192.168.0.32"), 80, "/img.pgm",
    buf, sizeof(buf),
    err_buf, sizeof(err_buf)
    );
if(result >= 0) {
    result = process_http_response(
        buf, result,
        &type,
        err_buf, sizeof(err_buf)
        );
}
if(result >= 0) {
    if(type == 3) {
        result = extract_pgm(
            buf, result,
            &width, &height, &bpp,
            err_buf, sizeof(err_buf)
            );
    else {
        fprintf(stdout, "wrong content type\n");
        exit(1);
    }
if(result >= 0) {
    /* process image here */
    ...
}
else {
    fprintf(stdout, "%s\n", err_buf);
    exit(1);
}
...

python-dtcam

This package is a Python binding to the C library (libdtcam). It provides cam class, to control and capture images from DTI interferometers.

Class cam

cam ( self, ip, port )
   Constructor.

Parameters:
   ip - ip address, string
   port - http server port, positive integer

Methods

get_frame ( self, uri )
   This method gets image from server

Parameters:
   uri - resource name, string (only pgm format is supported)

Return values:
   frame - image, numpy uint16 array

Usage

Image capture example
Import dtcam

cam = dtcam.cam("192.168.0.32", 80)
img = cam.get_frame("/img.pgm")
print img

Compiling & Installing

C library (libdtcam) is required
Compile module
python setup.py build
Compile under Windows with MinGW
python setup.py build -c mingw32
Install module
python setup.py install

matlab-dtcam

The matlab-dtcam binding module provides direct access to DTI interferometers from Matlab. This module is established through a MEX-file. Since each Matlab MEX-file is allowed to have only one entry point, dtcam implements control over single function using sub-functions. Depends on sub-function it is required to use variable number of "left hand side" and "right hand side" arguments. The first input argument determines sub-function.

Interface

[result1, result2, ... ] = dtcam ( subfunction, [parameter1, parameter2, ...] )

Sub-functions:
   0 - set communication parameters
   1 - get image
   2 - get phase map

set communication parameters

dtcam( uint8(0), ip, port )

Right hand side:
   ip - device ip adress, uint8 array of size 8
   port - server port, uint16

Left hand side:
   None

get image

dtcam( uint8(1), shift )

Right hand side:
   shift - phase shift, int16, optional

Left hand side:
   image - uint16 2D matrix

get phase map

dtcam( uint8(2), ref )

Right hand side:
   ref - phase shift reference points, int16 array of size 5

Left hand side:
   image - uint16 2D matrix

Usage

Set communication parameters, ip 192.168.0.32, port 80
dtcam(uint8(0), uint8([192,168,0,32]), uint16(80));
Get image
z = dtcam(uint8(1));
Get image with phase shift 50%
z = dtcam(uint8(1), int16(16384));
Get phase map and plot it
dtcam(uint8(0), uint8([192,168,0,32]), uint16(80));     % set device address
ref = int16([0., 0.212, 0.374, 0.538, 0.707] * 32768);  % reference points
z = dtcam(uint8(2), ref);                               % get phase map
z = uint8(z / 256);                                     % convert phase map to 8 bit data format
image(z)                                                % plot image
colormap(jet(256))                                      % set palette
axis off                                                % Remove axis ticks and numbers
axis image                                              % Set aspect ratio to obtain square pixels

Compiling

C library (libdtcam) is required
Compiling under Windows
mex dtcam.c ..\libdtcam\libdtcam.a wsock32.lib -I..\libdtcam
Compiling under Linux
mex dtcam.c ../libdtcam/libdtcam.a -I../libdtcam
Compiling for octave under Linux
mkoctfile --mex dtcam.c ../libdtcam/libdtcam.a -I../libdtcam

Requirements

matlab-dtcam

Matlab (with mex compiler) or
Octave (free software, mostly compatible with Matlab).

python-dtcam

Python 2.6 programming language
Numpy 1.5.1 (fundamental package needed for scientific computing with Python)

Links

Matlab http://www.mathworks.com/products/matlab/
Octave http://www.gnu.org/software/octave/
Python http://www.python.org
Numpy http://numpy.scipy.org

© 2010-2016 DENKTECH® | Home | About | Products | Tools | Downloads | Contacts |