00001 #ifndef Impala_Core_Array_KeypointsLowe_h
00002 #define Impala_Core_Array_KeypointsLowe_h
00003
00004 #include "Core/Array/Arrays.h"
00005 #include "Core/Array/RGB2Intensity.h"
00006 #include "Core/Array/PixMax.h"
00007 #include "Link/LoweSift/LoweKeypoints.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace Array
00014 {
00015
00016
00017
00018
00019 void
00020 KeypointsLowe(Array2dScalarReal64*& points, Array2dScalarUInt8*& featVecs,
00021 Array2dVec3UInt8* src, bool doFeatVecs)
00022 {
00023 using namespace Impala::Link::LoweSift;
00024
00025 Array2dScalarReal64* rData = 0;
00026 RGB2Intensity(rData, src);
00027 Real64 maxVal = PixMax(rData);
00028
00029 int width = src->CW();
00030 int height = src->CH();
00031 Image im = CreateImage(height, width, IMAGE_POOL);
00032 Real64* dataPtr = rData->CPB();
00033 for (int r = 0; r < height; r++)
00034 for (int c = 0; c < width; c++)
00035 im->pixels[r][c] = *dataPtr++ / maxVal;
00036 delete rData;
00037
00038 LoweKeypoints loweKeypoints;
00039 Keypoint keys = loweKeypoints.GetKeypoints(im);
00040
00041 int nrPoints = 0;
00042 for (Keypoint k = keys; k != NULL; k = k->next)
00043 nrPoints++;
00044
00045 if (!points || (points->CW() != 4) || (points->CH() != nrPoints))
00046 {
00047 delete points;
00048 points = new Array2dScalarReal64(4, nrPoints, 0, 0);
00049 }
00050 if (!featVecs || (featVecs->CW() != LoweKeypoints::VecLength) ||
00051 (featVecs->CH() != nrPoints))
00052 {
00053 if (doFeatVecs)
00054 {
00055 delete featVecs;
00056 featVecs = new Array2dScalarUInt8(LoweKeypoints::VecLength,
00057 nrPoints, 0, 0);
00058 }
00059 }
00060
00061 int row = 0;
00062 for (Keypoint srcK = keys ; srcK != NULL; srcK = srcK->next)
00063 {
00064 Real64* pointPtr = points->CPB(0, row);
00065 *pointPtr++ = srcK->col;
00066 *pointPtr++ = srcK->row;
00067 *pointPtr++ = srcK->scale;
00068 *pointPtr++ = srcK->ori;
00069 if (doFeatVecs)
00070 {
00071 UInt8* featPtr = featVecs->CPB(0, row);
00072 for (int i = 0; i < LoweKeypoints::VecLength; i++)
00073 *featPtr++ = srcK->ivec[i];
00074 }
00075 row++;
00076 }
00077 }
00078
00079 }
00080 }
00081 }
00082
00083 #endif