Professional Documents
Culture Documents
Current Scenario
Mobile cameras are widespread
Main uses for camera: capturing images/videos
Still significant barriers to create new
applications
There is not enough support for
camera/imaging in S60 SDK
Only a handful of small companies making
camera apps. Most of these are experts
computer vision expertise, image/signal
processing experience
Prior work
Goal
Internally to be used in imaging products, as a
research test bed, etc.
Externally to provide developers in binary form
to facilitate third-party imaging
Intels OpenCV is the desktop version of what
NCV will become for mobiles
Full functionality
Wide range of imaging operations, however some not
possible on mobile (yet)
NokiaCVs main difference: supports operations that
are useful and fast right now.
Use Cases
Capture Enhancement
Image color conversions, imaging wrapper to modify images easily
and manipulate pixels directly and easily
Building blocks present for developers to make high-quality stitching
algorithms for panoramas
Building blocks present for developers to implement complex
algorithms without requiring the building and debugging of a
platform
Gaming/UI
Provides robust motion estimation as a software
component, ready for games and applications
Post-capture editing
Image warping operation provided to create
standard warping or in other entertainment uses
Image compositing provided to add items to
captured images
Functional Blocks
CCamus
CEgoMovement
CEigenvalues
CFixed
CImageOp
CImageOperations
CImagePyramid
CImageStatistics
CMotionHistoryImage
CNokiaCVImage
CNokiaCVMath
CNokiaCVMatrix
CArithmeticOp
CColorConversionOp
CComparisonOp
CConvolutionOp
CCornerDetectionOp
CEdgeDetectionOp
CGaussianSmoothOp
CMedianFilterOp
CMorphologicalOp
CResizeOp
CRotationOp
CShearOp
CTemplateMatchOp
CThresholdOp
CWarpOp
CNokiaCVVector
COpticalFlow
CPixelAccess
CPixelColorModel
CSVD
TColorModel
CHsvColorModel
CLabColorModel
CLmsColorModel
CRgbColorModel
CXyzColorModel
CYuvColorModel
API Overview
This library extends the image processing and math capabilities of
the Symbian Series 60 platform, targeted for applications using
computer vision techniques on camera phones.
The library provides an image class, CNokiaCVImage for handling
RGB, grayscale and black and white images. Provides functions to
perform arithmetic operations, transformations, feature extraction,
color conversions. In addition, operations to compute image
statistics such as histograms and pixel color means are provided.
The library has two algorithms (CCamus and CMotionHistoryImage)
to determine motion estimates and history.
Matrix and vector classes CNokiaCVMatrix and CNokiaCVVector
allow creation of matrices and vectors of arbitrary dimensionality.
Math operations and some linear algebra techniques that work with
these classes are available in the library.
Library Features
CNokiaCVImage Class
CNokiaCVImage is a wrapper for CFbsBitmap that is
provided by the platform. This class provides
DisplayMode independent access to the pixel data.
CFbsBitmap* iInternalBitmap;
Usage examples:
// load from file
CNokiaCVImage* incvBitmap = CNokiaCVImage::NewL();
TRAPD(err1, incvBitmap->CreateL( *aImageFullName )); ...
// draw bitmap
CWindowGc& gc = SystemGc();
gc.BitBlt( TPoint( 0,0 ), incvBitmap-> Bitmap() );
Functions
static IMPORT_C CNokiaCVImage*
CNokiaCVImage::NewLC ( ) ; Implements two-phase
construction functions (NewLC(), ConstructL()) to
create a new instance of the object.
Returns: CNokiaCVImage*
IMPORT_C void CNokiaCVImage::CreateL (const TDesC
& aFileName ) ; Create image from a file.
static IMPORT_C void CNokiaCVImage::Copy
(CNokiaCVImage * aSource, CNokiaCVImage * aTarget,
TInt aBlendingRatio = 100 ); Copy a source image
to the target image.
CPixelAccess Class
CPixelAccess class provides access to
CNokiaCVImage on a pixel-level. Derived from
TBitmapUtil.
Example:
CPixelAccess* out = CPixelAccess::NewL(aTarget);
CPixelAccess* in = CPixelAccess::NewL(iImage, out);
...
in->SetPos( TPoint( rotX, rotY ) );
out->SetPos(TPoint( x, y ) );
out->SetRGB( in->GetRGB() ); // set pixel value from in
to out
...
delete out;
delete in;
Functions
static IMPORT_C CPixelAccess* CPixelAccess::NewLC
(CNokiaCVImage * aImage ) ; Constructor. Sets the
current pixel position to (0,0) position.
IMPORT_C TUint32 CPixelAccess::GetRGB ( ) ; Return
pixel from the current position as a RGB.
IMPORT_C void CPixelAccess::SetRGB
(TUint32 aPixel ) ; Set pixel to the current
position.
Parameters:
aPixel RGB value as TUint32 in format used by
TRgb: 0x00BBGGRR
CPixelColorModel Class
IMPORT_C TUint8 CPixelColorModel::Red ( ) ; Get
the red component;
Returns: TUint8 Red-component
IMPORT_C CYuvColorModel CPixelColorModel::ToYUV
( ) ; Convert to YUV.
Returns: CYuvColorModel.
IMPORT_C CHsvColorModel CPixelColorModel::ToHSV
( ) ;
Convert to HSV
return CHsvColorModel
TColorModel Class
class CRgbColorModel : public TColorModel
{
public:
TInt iR;
TInt iG;
TInt iB;
};
CNokiaCVMath Class
This class gathers some utility functions in one place.
static IMPORT_C TInt SinLUT_Rad (TReal
&aTrg, const TReal &aSrc) Computes Sin
using lookup table.
static IMPORT_C TInt TanLUT_Rad (TReal
&aTrg, const TReal &aSrc) Computes Tan
using lookup table.
CNokiaCVMatrix Class
Fixed point matrix representation. Usage:
CNokiaCVMatrix* m = CNokiaCVMatrix->NewLC(5,5);
(*m)(3,3) = 2; (*m)(2,3) = 4.23;
CNokiaCVMatrix* n = CNokiaCVMatrix->Ones(5,5);
CleanupStack::PushL(n);
CNokiaCVMatrix *res = (*m)*(*n)*5;
CleanupStack::PushL(res);
CFixed det = res->Det();
...
CleanupStack::Pop(m); CleanupStack::Pop(n);
CleanupStack::Pop(res);
delete m; delete n; delete res;
Functions
static IMPORT_C CNokiaCVMatrix * NewL (const TInt
aRows, const TInt aCols) Creates a new matrix
according to size given with initial value zero.
IMPORT_C CNokiaCVMatrix * Inverse ()
const Calculates the inverse matrix of this
matrix.
IMPORT_C CFixed ** Eigenvalues () Calculates the
eigenvalues of this matrix.
IMPORT_C CFixed * Singularvalues () Calculates the
singular values of this matrix using ncvSVD.
CSVD Class
Singular value decomposition of a given real matrix.
Householder bidiagonalization and a variant of the QR algorithm are
used.
The SVD algorithm is derived from JAMA/TNT, the Java Matrix
Package.
Usage:
CNokiaCVMatrix *a = CNokiaCVMatrix::NewL(rows,cols);
CSVD *svd;
TRAPD(err, svd = CSVD::NewL(*a))
... //Handle possible errors
CNokiaCVMatrix *v = svd->V();
...
delete a; delete svd; delete v;
CNokiaCVVector Class
CMotionHistoryImage Class
This class computes a motion history image (MHI) for a series of
input frames. The MHI is a grayscale bitmap in which recently
moved pixels are represent with bright values and "older" with
darker values. Frame-by-frame the values from previous frames are
decayed linearly.
Functions
static IMPORT_C CMotionHistoryImage * NewL
(CNokiaCVImage &aImage, const TInt
aHistorySize) Construct CMotionHistoryImage from the
first image of motion history.
Parameters:
COpticalFlow Class
The optical flow class: motion estimations for each pixel.
This class also implements methods for calculating
higher level information from the optical flow.
Friends class CCamus: Camus algorithm for
estimation of optical flow from a series of bitmaps.
Member CEgoMovement Class: class for pixel motion
estimation values.
CFixed iX Movement along the x-axis.
CFixed iY Movement along the y-axis.
Functions
static IMPORT_C COpticalFlow * NewL (const TSize
&aImageSize) Factory method for creating an
instance.
Parameters:
aImageSize Size of the optical flow map
Functions
void SetCamusOpts (const TInt aCamusOpts) Set
runtime parameters of the Camus motion estimation
algorithm.
IMPORT_C CEgoMovement (const CFixed aX, const
CFixed aY) Constructor.
IMPORT_C CFixed Norm () Calculates the euclidian
norm of the movement.
CImagePyramid Class
Creates a Laplacian or Gaussian image pyramid from a given
bitmap.
IMPORT_C CNokiaCVImage * LevelImage (TInt
aLevel) Getter for an image of certain level.
Returns:
CNokiaCVImage* Pointer to the level image
CImageStatistics Class
m00
m01
m10
m11
m20
M02
Usage:
TReal mean; CImageStatistics::Mean(*iSourceBitmap, mean,
(TChannel)aChannel);
Functions
static IMPORT_C void Histogram (CNokiaCVImage
&aImage, THistogram &aArray, TChannel
aChannel=EGrayChannel) Calculate the histogram
from a CNokiaCVImage.
static IMPORT_C void Mean (CNokiaCVImage &aImage,
TReal &aMean, TChannel
aChannel=EAllChannels) Calculate the mean of
CNokiaCVImage.
static IMPORT_C void StDev (CNokiaCVImage &aImage,
TReal &aStDev, TReal &aMean, TChannel
aChannel) Calculate the standard deviation of a
CNokiaCVImage.
CImageOperations Class
Provides an simplified access to image operations. Each operation
is a static method that creates and returns the result bitmap.
Usage
CNokiaCVImage* iTarget =
CImageOperations::Rotate(iSource, 45);
...
delete iTarget;
Functions
static IMPORT_C CNokiaCVImage * Resize (CNokiaCVImage
*aSource, TSize aSize, TBool aBilinear=EFalse) Resizes
the source image. See CResizeOp for more information.
static IMPORT_C CNokiaCVImage * Convolution
(CNokiaCVImage *aSource, CNokiaCVMatrix &aKernel, TInt
aNormFactor) Performs convolution of CNokiaCVImage and a
kernel (CNokiaCVMatrix).
static IMPORT_C CNokiaCVImage * Gaussian (CNokiaCVImage
*aSource, TUint aSize) Gaussian smoothing filter.
static IMPORT_C CNokiaCVImage * EdgeDetectLaplacian
(CNokiaCVImage *aSource) Laplacian edge detection
filter. See CEdgeDetectionOp for more info.
CCamus Class
Implements the Camus algorithm for estimation of optical flow from a series
of bitmaps. This class creates an COpticalFlow object that contains an
estimation of the motion vector (x and y motion in pixels) for each pixel of
the input frame.
Can use the methods of COpticalFlow to extract higher level information
such as estimated camera rotation/movement.
The algorithm is highly parameterizable.
Features of the algorithm and some hints:
Maximum estimated motion is 1 or 2 pixels/frame, so it is typically reasonable to
use small bitmaps (e.g. 16x12 pixels).
History of several frames is used to achieve sub pixel accuracy
Based on template matching
Uses grayscale images
Large motions are hard so having a good frame rate is essential since the perframe motion is inversely proportional to the frame rate
Small bitmaps are preferred (especially when estimation of quick movements is
required) as its faster to compute; higher frame rate.
Camus Algorithm
Basic idea:
Simple technique to perform optical flow
computations using correlation or patchmaking methods. The idea here is to match
features between images and computing the
SD (sum-difference) of patches.
Reference: T. Camus, Real-Time Optical
Flow, PhD Thesis, Brown University
Technical Report CS-94-36, 1994.
Functions
static IMPORT_C CCamus* CCamus::NewL
(CNokiaCVImage & aImage,
const TInt aHistorySize =
KDefaultCamusHistorySize )
CEgoMovement Class
Simple vector-like wrapper class for pixel
motion estimation values.
Functions
IMPORT_C CEgoMovement::CEgoMovement (const
CFixed aX, const CFixed aY )Constructor.
Parameters:
aX Movement along the x-axis.
aY Movement along the y-axis.
Returns:
Dot product value.
CEigenValues Class
Eigenvalue decomposition of a real matrix.
Usage:
CNokiaCVMatrix * matrix = ...; CEigenvalues *
eigs;
TRAPD(err, eigs = CEigenvalues->NewL(matrix));
if(err != KErrNone) {
//eigs not found do something
}
else {
TReal * real = eigs->RealEigenvalues();
delete eigs;
} ...
Functions
IMPORT_C TReal*
CEigenvalues::RealEigenvalues ( )
Getter for the real part of the
eigenvalues (iD).
Returns:
the real part of the eigenvalues in an array
IMPORT_C TReal*
CEigenvalues::ImaginaryEigenvalues ( )
Getter for the imaginary part of the
eigenvalues (iE).
Returns:
the imaginary part of the eigenvalues in an
array
CFixed Class
Fixed point class.
The class implements basic arithmetic for
fixed point numbers.
CFixed can be used instead of TReal
when performance more critical than
accuracy.
CImageOp Class
Image operations interface.
This class represents an interface that all image operation classes
must implement. Most of the operations implementing this interface
are also included in CImageOperations.
There are various image operations that implement this interface,
e.g. for rotating, scaling and filtering bitmap.
Usage example (CRotationOp):
iSource = ....
iTargetMode = EGray256;
iTarget1 = CNokiaCVImage::NewL();
iTarget1->CreateL(iCurrSource->Size(),
iTargetMode);
CRotationOp op(iCurrSource, 90);
op.DoOperation(iTarget1); ...
Functions
virtual IMPORT_C void CImageOp::DoOperation
(CNokiaCVImage * aTarget ) [pure virtual]
All image operations must implement this method. This method does
the actual operation.
Typically you need to allocate and create the target bitmap yourself
before doing the operation
Parameters:
aTarget target bitmap
Note:
the function can leave
CArithmeticOp
CArithmeticOp provides basic arithmetic operations for
CNokiaCVImages.
Target and source bitmaps must be of same size.
Usage:
IMPORT_C void CArithmeticOp::DoOperation
(CNokiaCVImage * aTarget )
Does the actual operation.
Parameters:
aTarget CNokiaCVImage to store the result in. Must be allocated
and created beforehand.
Implements CImageOp.
CColorConversionOp Class
Provides CNokiaCVImage with color
conversions.
Functions
IMPORT_C CColorConversionOp::CColorConversionOp
(CNokiaCVImage * aImage, TDisplayMode aTargetMode )
Constructor. Converts given image to given display mode.
Parameters:
aImage Image to convert aTargetMode Target display mode Valid
TDisplayModes for aTargetMode are:
EGray2
EGray4
EGray16
EGray256
EColor4K
EColor64K
EColor16M
CComparisonOp Class
Provides CNokiaCVImage with pixel-wise image
comparison operations: "greater than", "less
than" and "equal".
Matching pixels are set white. Non-matching and
pixels outside the comparison region are set
black.
Valid values are:
EGreater
ELess
EEqual
Functions
aImage1 images to compare aImage2 another images to compare. These two images must
be of same bit depth and same size
aComparison Comparison operation: .EGreater, ELess or EEqual
aSubregion subregion of images 1 and 2 that are compared
aTarget CNokiaCVImage to store the result in. The target bitmap must be black and white.
CConvolutionOp Class
Convolution operation.
Performs convolution of CNokiaCVImage
and a kernel (CNokiaCVMatrix).
Functions
IMPORT_C CConvolutionOp::CConvolutionOp
(CNokiaCVImage * aImage, CNokiaCVMatrix
& aKernel ) Constructor.
Parameters:
aImage CNokiaCVImage to use as source
aKernel CNokiaCVMatrix Kernel to use for convolution. Only 3x3
and 5x5 matrices are supported.
CCornerDetectionOp
Corner detection for CNokiaCVImage.
Moravec corner detector is implemented.
Defines interest points as points where there
is a large intensity variation in every direction
i.e. corners.
Functions
IMPORT_C CCornerDetectionOp::CCornerDetectionOp
(CNokiaCVImage * aImage,
TCornerDetectionMethod aMethod = EMoravec,
TInt aNeighborhoodSize = 20, TInt aConstant = 25 )
Constructor.
Parameters:
aImage CNokiaCVImage to detect from
aMethod Which corner detection method to use
aNeighborhoodSize Size of the neighborhood to use for adaptive
thresholding
aConstant a constant value to subtract from the mean threshold
CEdgeDetectionOp
Edge detection filters using convolution.
Possible values are:
ESobel
EPrewitt
ELaplacian
ECanny
Functions
IMPORT_C
CEdgeDetectionOp::CEdgeDetectionOp
(CNokiaCVImage * aImage,
TEdgeDetectionMethod aMethod ) Constructor.
Parameters:
aImage CNokiaCVImage to detect from aMethod Which edge
detection method to use
IMPORT_C void
CEdgeDetectionOp::DoOperation
(CNokiaCVImage * aTarget )
Parameters:
aTarget CNokiaCVImage to store the result
CGaussianSmoothOp
Gaussian smoothing operator.
The Gaussian smoothing operator is a 2-D
convolution operator used to `blur' images
and remove detail and noise.
The shape of the kernel represents the
shape of a Gaussian (`bell-shaped') pointspread function.
5 X 5 Gaussian Kernel
Functions
IMPORT_C
CGaussianSmoothOp::CGaussianSmoothOp
(CNokiaCVImage * aImage,
TInt aKernelSize ) Constructor.
Parameters:
aImage CNokiaCVImage a source image aKernelSize The
number of rows and columns in Gaussian kernel: Possible
values are. 3 and 5.
IMPORT_C void
CGaussianSmoothOp::DoOperation
(CNokiaCVImage * aTarget )
Parameters:
aTarget CNokiaCVImage to store the result
CMedianFilterOp
Functions
IMPORT_C CMedianFilterOp::CMedianFilterOp
(CNokiaCVImage * aImage,
TInt aKernelRows ) Constructor.
Parameters:
aImage CNokiaCVImage to use as source aKernelRows How
big a kernel to use. Possible values are:
3 for 3x3
5 for 5x5
7 for 7x7
CMorphologicalOp Class
Dilation/Erosion filter.
Here, the state of any given pixel in the output image is
determined by applying a rule to the corresponding pixel
and its neighbors in the input image. The rule used to
process the pixels defines the operation as a dilation or
an erosion.
Dilation: The value of the output pixel is the maximum
value of all the pixels in the input pixel's neighborhood.
In a binary image, if any of the pixels is set to the value
1, the output pixel is set to 1.
Erosion: The value of the output pixel is the minimum
value of all the pixels in the input pixel's neighborhood.
In a binary image, if any of the pixels is set to 0, the
output pixel is set to 0.
Functions
IMPORT_C CMorphologicalOp::CMorphologicalOp
(CNokiaCVImage * aImage, CNokiaCVMatrix & aStruct,
TMorphologicalOperation aOperation ) Constructor.
Parameters:
aImage CNokiaCVImage to use as source
aStruct CNokiaCVMatrix a structuring element to use for morphing
aOperation Which operation to do
CResizeOp Class
Resizes the CNokiaCVImage.
IMPORT_C CResizeOp
(CNokiaCVImage *aImage, TBool
aBilinear=EFalse) Constructor.
IMPORT_C void DoOperation
(CNokiaCVImage *aTarget)
CRotationOp Class
Rotates a CNokiaCVImage.
Implements an arbitrary angle rotation.
IMPORT_C CRotationOp
(CNokiaCVImage *aImage, TInt
aAngle) Constructor.
IMPORT_C void DoOperation
(CNokiaCVImage *aTarget)
Do the actual operation.
CShearOp Class
Shear operation for CNokiaCVImage.
Shears bitmap Horizontally or Vertically (creates
a parallelogram).
IMPORT_C CShearOp (CNokiaCVImage
*aImage, TInt aAngle, TDirection
aDirection=EHorizontal) Constructor.
IMPORT_C void DoOperation
(CNokiaCVImage *aTarget)
Do the actual operation.
CTemplateMatch Class
Template matching operation for two CNokiaCVImages.
Used for finding small parts of an image that match a
template image.
Algorithm:
This method is implemented by first creating a subimage (the
template).
The center of the subimage is simply moved over each (x,y)
point in the a candidate image.
The sum of products between the coefficients in the candidate
image and the corresponding neighborhood pixels in the area
spanned by the template is calculated to determine best match.
Functions
IMPORT_C CTemplateMatchOp::CTemplateMatchOp
(CNokiaCVImage * aImage, CNokiaCVImage * aTemplate )
Constructor for template matching operation.
Parameters:
aImage CNokiaCVImage to match against aPattern
CNokiaCVImage containing the template to match
Implements CImageOp.
CThresholdOp
Functions
CWarpOp Class
Provides CNokiaCVImage with a warp operation The
result of the operation is like dragging an elastic image
from one point to a given direction.
IMPORT_C CWarpOp::CWarpOp (CNokiaCVImage
* aImage, TPoint aSource,
TPoint aDestination )
Constructor.
Parameters:
aImage Source image. aSource Source point to start the warp
from. aDestination Destination point to warp towards.
Demos
Outline
Cube
Motion Estimation
Image Processing
Game
Cube
Using a cube to represent camera movement
Obtaining optical flow using Camus algorithm
Mean movement of optical flow Cubes movement
along x and y
Mean rotation of optical flow Cubes rotation
Depth info: movement along z axis Cubes size
CCamus
CEgoMovement
COpticalFlow
CNokiaCVImage
CPixelAccess
Motion Estimation
Calculate and display motion history image
Calculate optical flow, indicate horizontal and
vertical motion
NokiaCV classes used
CMotionHistoryImage
CNokiaCVImage
CCamus
COpticalFlow
Image Processing
Loads two images
Perform image processing based on user
selection
NokiaCV classes used
All image processing classes