Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
07eed8c4
Commit
07eed8c4
authored
Jul 12, 2011
by
Evgeniy Kozinov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring latentSVM
parent
ea8e2796
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
354 additions
and
408 deletions
+354
-408
objdetect.hpp
modules/objdetect/include/opencv2/objdetect/objdetect.hpp
+6
-10
_latentsvm.h
modules/objdetect/src/_latentsvm.h
+3
-6
_lsvm_error.h
modules/objdetect/src/_lsvm_error.h
+1
-0
_lsvm_routine.h
modules/objdetect/src/_lsvm_routine.h
+3
-3
_lsvm_types.h
modules/objdetect/src/_lsvm_types.h
+14
-19
featurepyramid.cpp
modules/objdetect/src/featurepyramid.cpp
+236
-290
latentsvm.cpp
modules/objdetect/src/latentsvm.cpp
+4
-5
lsvmparser.cpp
modules/objdetect/src/lsvmparser.cpp
+1
-2
matching.cpp
modules/objdetect/src/matching.cpp
+37
-37
routine.cpp
modules/objdetect/src/routine.cpp
+49
-36
No files found.
modules/objdetect/include/opencv2/objdetect/objdetect.hpp
View file @
07eed8c4
...
...
@@ -160,9 +160,9 @@ CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade,
// (x, y) - coordinate in level l
typedef
struct
{
unsigned
int
x
;
unsigned
int
y
;
unsigned
int
l
;
int
x
;
int
y
;
int
l
;
}
CvLSVMFilterPosition
;
// DataType: STRUCT filterObject
...
...
@@ -179,16 +179,12 @@ typedef struct
// used formula H[(j * sizeX + i) * p + k], where
// k - component of feature vector in cell (i, j)
// END OF FILTER DESCRIPTION
// xp - auxillary parameter for internal use
// size of row in feature vectors
// (yp = (int) (p / xp); p = xp * yp)
typedef
struct
{
CvLSVMFilterPosition
V
;
float
fineFunction
[
4
];
unsigned
int
sizeX
;
unsigned
int
sizeY
;
unsigned
int
p
;
unsigned
int
xp
;
int
sizeX
;
int
sizeY
;
int
numFeatures
;
float
*
H
;
}
CvLSVMFilterObject
;
...
...
modules/objdetect/src/_latentsvm.h
View file @
07eed8c4
...
...
@@ -37,10 +37,7 @@
// RESULT
// Error status
*/
int
getFeaturePyramid
(
IplImage
*
image
,
const
int
lambda
,
const
int
k
,
const
int
startX
,
const
int
startY
,
const
int
W
,
const
int
H
,
CvLSVMFeaturePyramid
**
maps
);
int
getFeaturePyramid
(
IplImage
*
image
,
CvLSVMFeaturePyramid
**
maps
);
/*
// Getting feature map for the selected subimage
...
...
@@ -55,7 +52,7 @@ int getFeaturePyramid(IplImage * image,
// RESULT
// Error status
*/
int
getFeatureMaps
_dp
(
const
IplImage
*
image
,
const
int
k
,
CvLSVMFeatureMap
**
map
);
int
getFeatureMaps
(
const
IplImage
*
image
,
const
int
k
,
CvLSVMFeatureMap
**
map
);
/*
...
...
@@ -71,7 +68,7 @@ int getFeatureMaps_dp(const IplImage * image, const int k, CvLSVMFeatureMap **ma
// RESULT
// Error status
*/
int
normaliz
ationAndTruncationFeatureMaps
(
CvLSVMFeatureMap
*
map
,
const
float
alfa
);
int
normaliz
eAndTruncate
(
CvLSVMFeatureMap
*
map
,
const
float
alfa
);
/*
// Feature map reduction
...
...
modules/objdetect/src/_lsvm_error.h
View file @
07eed8c4
...
...
@@ -2,6 +2,7 @@
#define LSVM_ERROR
#define LATENT_SVM_OK 0
#define LATENT_SVM_MEM_NULL 2
#define DISTANCE_TRANSFORM_OK 1
#define DISTANCE_TRANSFORM_GET_INTERSECTION_ERROR -1
#define DISTANCE_TRANSFORM_ERROR -2
...
...
modules/objdetect/src/_lsvm_routine.h
View file @
07eed8c4
...
...
@@ -13,18 +13,18 @@
// Error status is return value
//////////////////////////////////////////////////////////////
int
allocFilterObject
(
CvLSVMFilterObject
**
obj
,
const
int
sizeX
,
const
int
sizeY
,
const
int
p
,
const
int
xp
);
const
int
p
);
int
freeFilterObject
(
CvLSVMFilterObject
**
obj
);
int
allocFeatureMapObject
(
CvLSVMFeatureMap
**
obj
,
const
int
sizeX
,
const
int
sizeY
,
const
int
p
,
const
int
xp
);
const
int
p
);
int
freeFeatureMapObject
(
CvLSVMFeatureMap
**
obj
);
#ifdef __cplusplus
extern
"C"
#endif
int
allocFeaturePyramidObject
(
CvLSVMFeaturePyramid
**
obj
,
const
int
lambda
,
const
int
countLevel
);
const
int
countLevel
);
#ifdef __cplusplus
extern
"C"
...
...
modules/objdetect/src/_lsvm_types.h
View file @
07eed8c4
...
...
@@ -14,7 +14,7 @@
// The number of elements in bin
// The number of sectors in gradient histogram building
#define
CNTPARTION
9
#define
NUM_SECTOR
9
// The number of levels in image resize procedure
// We need Lambda levels to resize image twice
...
...
@@ -23,6 +23,8 @@
// Block size. Used in feature pyramid building procedure
#define SIDE_LENGTH 8
#define VAL_OF_TRUNCATE 0.2f
//////////////////////////////////////////////////////////////
// main data structures //
//////////////////////////////////////////////////////////////
...
...
@@ -30,31 +32,24 @@
// DataType: STRUCT featureMap
// FEATURE MAP DESCRIPTION
// Rectangular map (sizeX x sizeY),
// every cell stores feature vector (dimension =
p
)
//
H
- matrix of feature vectors
// every cell stores feature vector (dimension =
numFeatures
)
//
map
- matrix of feature vectors
// to set and get feature vectors (i,j)
// used formula
M
ap[(j * sizeX + i) * p + k], where
// used formula
m
ap[(j * sizeX + i) * p + k], where
// k - component of feature vector in cell (i, j)
// END OF FEATURE MAP DESCRIPTION
// xp - auxillary parameter for internal use
// size of row in feature vectors
// (yp = (int) (p / xp); p = xp * yp)
typedef
struct
{
int
sizeX
;
int
sizeY
;
int
p
;
int
xp
;
float
*
Map
;
int
numFeatures
;
float
*
map
;
}
CvLSVMFeatureMap
;
// DataType: STRUCT featurePyramid
//
// countLevel - number of levels in the feature pyramid
// lambda - resize scale coefficient
// numLevels - number of levels in the feature pyramid
// pyramid - array of pointers to feature map at different levels
typedef
struct
{
int
countLevel
;
int
lambda
;
int
numLevels
;
CvLSVMFeatureMap
**
pyramid
;
}
CvLSVMFeaturePyramid
;
...
...
@@ -74,14 +69,14 @@ typedef struct{
// DataType: STRUCT fftImage
// The structure stores FFT image
//
//
p
- number of channels
//
numFeatures
- number of channels
// x - array of FFT images for 2d signals
// n - number of rows
// m - number of collums
typedef
struct
{
unsigned
int
p
;
unsigned
int
dimX
;
unsigned
int
dimY
;
int
numFeatures
;
int
dimX
;
int
dimY
;
float
**
channels
;
}
CvLSVMFftImage
;
...
...
modules/objdetect/src/featurepyramid.cpp
View file @
07eed8c4
...
...
@@ -10,13 +10,6 @@
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
static
inline
int
sign
(
float
r
)
{
if
(
r
>
0.0001
f
)
return
1
;
if
(
r
<
-
0.0001
f
)
return
-
1
;
return
0
;
}
/*
// Getting feature map for the selected subimage
//
...
...
@@ -30,115 +23,132 @@ static inline int sign(float r)
// RESULT
// Error status
*/
int
getFeatureMaps
_dp
(
const
IplImage
*
image
,
const
int
k
,
CvLSVMFeatureMap
**
map
)
int
getFeatureMaps
(
const
IplImage
*
image
,
const
int
k
,
CvLSVMFeatureMap
**
map
)
{
int
sizeX
,
sizeY
;
int
p
,
px
,
str
sz
;
int
height
,
width
,
c
hannels
;
int
p
,
px
,
str
ingSize
;
int
height
,
width
,
numC
hannels
;
int
i
,
j
,
kk
,
c
,
ii
,
jj
,
d
;
float
*
datadx
,
*
datady
;
float
tmp
,
x
,
y
,
tx
,
ty
;
//
int
ch
;
//
float
magnitude
,
x
,
y
,
tx
,
ty
;
IplImage
*
dx
,
*
dy
;
int
*
nearest
_x
,
*
nearest_y
;
int
*
nearest
;
float
*
w
,
a_x
,
b_x
;
float
kernel
[
3
]
=
{
-
1.
f
,
0.
f
,
1.
f
};
// x y
float
kernel
[
3
]
=
{
-
1.
f
,
0.
f
,
1.
f
};
CvMat
kernel_dx
=
cvMat
(
1
,
3
,
CV_32F
,
kernel
);
CvMat
kernel_dy
=
cvMat
(
3
,
1
,
CV_32F
,
kernel
);
//
float
*
r
;
int
*
alfa
;
//
//
//
int
*
alfa
;
float
boundary_x
[
CNTPARTION
+
1
];
float
boundary_y
[
CNTPARTION
+
1
];
float
max
,
tmp_scal
;
int
maxi
;
//
float
boundary_x
[
NUM_SECTOR
+
1
];
float
boundary_y
[
NUM_SECTOR
+
1
];
float
max
,
dotProd
;
int
maxi
;
height
=
image
->
height
;
width
=
image
->
width
;
height
=
image
->
height
;
width
=
image
->
width
;
channels
=
image
->
nChannels
;
numChannels
=
image
->
nChannels
;
dx
=
cvCreateImage
(
cvSize
(
image
->
width
,
image
->
height
)
,
IPL_DEPTH_32F
,
3
);
dy
=
cvCreateImage
(
cvSize
(
image
->
width
,
image
->
height
)
,
IPL_DEPTH_32F
,
3
);
dx
=
cvCreateImage
(
cvSize
(
image
->
width
,
image
->
height
),
IPL_DEPTH_32F
,
3
);
dy
=
cvCreateImage
(
cvSize
(
image
->
width
,
image
->
height
),
IPL_DEPTH_32F
,
3
);
sizeX
=
width
/
k
;
sizeY
=
height
/
k
;
px
=
CNTPARTION
+
2
*
CNTPARTION
;
//
px
=
3
*
NUM_SECTOR
;
//
p
=
px
;
str
sz
=
sizeX
*
p
;
allocFeatureMapObject
(
map
,
sizeX
,
sizeY
,
p
,
px
);
str
ingSize
=
sizeX
*
p
;
allocFeatureMapObject
(
map
,
sizeX
,
sizeY
,
p
);
cvFilter2D
(
image
,
dx
,
&
kernel_dx
,
cvPoint
(
-
1
,
0
));
cvFilter2D
(
image
,
dy
,
&
kernel_dy
,
cvPoint
(
0
,
-
1
));
for
(
i
=
0
;
i
<=
CNTPARTION
;
i
++
)
cvFilter2D
(
image
,
dx
,
&
kernel_dx
,
cvPoint
(
-
1
,
0
));
cvFilter2D
(
image
,
dy
,
&
kernel_dy
,
cvPoint
(
0
,
-
1
));
float
arg_vector
;
for
(
i
=
0
;
i
<=
NUM_SECTOR
;
i
++
)
{
boundary_x
[
i
]
=
cosf
((((
float
)
i
)
*
(((
float
)
PI
)
/
(
float
)
(
CNTPARTION
))));
boundary_y
[
i
]
=
sinf
((((
float
)
i
)
*
(((
float
)
PI
)
/
(
float
)
(
CNTPARTION
))));
}
/*for(i = 0; i <= CNTPARTION; i++) */
arg_vector
=
(
(
float
)
i
)
*
(
(
float
)(
PI
)
/
(
float
)(
NUM_SECTOR
)
);
boundary_x
[
i
]
=
cosf
(
arg_vector
);
boundary_y
[
i
]
=
sinf
(
arg_vector
);
}
/*for(i = 0; i <= NUM_SECTOR; i++) */
r
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
width
*
height
));
alfa
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
(
width
*
height
*
2
));
for
(
j
=
1
;
j
<
height
-
1
;
j
++
)
for
(
j
=
1
;
j
<
height
-
1
;
j
++
)
{
datadx
=
(
float
*
)(
dx
->
imageData
+
dx
->
widthStep
*
j
);
datady
=
(
float
*
)(
dy
->
imageData
+
dy
->
widthStep
*
j
);
for
(
i
=
1
;
i
<
width
-
1
;
i
++
)
datadx
=
(
float
*
)(
dx
->
imageData
+
dx
->
widthStep
*
j
);
datady
=
(
float
*
)(
dy
->
imageData
+
dy
->
widthStep
*
j
);
for
(
i
=
1
;
i
<
width
-
1
;
i
++
)
{
c
=
0
;
x
=
(
datadx
[
i
*
channels
+
c
]);
y
=
(
datady
[
i
*
channels
+
c
]);
c
=
0
;
x
=
(
datadx
[
i
*
numChannels
+
c
]);
y
=
(
datady
[
i
*
numChannels
+
c
]);
r
[
j
*
width
+
i
]
=
sqrtf
(
x
*
x
+
y
*
y
);
for
(
kk
=
1
;
kk
<
channels
;
kk
++
)
r
[
j
*
width
+
i
]
=
sqrtf
(
x
*
x
+
y
*
y
);
for
(
ch
=
1
;
ch
<
numChannels
;
ch
++
)
{
tx
=
(
datadx
[
i
*
channels
+
kk
]);
ty
=
(
datady
[
i
*
channels
+
kk
]);
tmp
=
sqrtf
(
tx
*
tx
+
ty
*
ty
);
if
(
tmp
>
r
[
j
*
width
+
i
])
tx
=
(
datadx
[
i
*
numChannels
+
ch
]);
ty
=
(
datady
[
i
*
numChannels
+
ch
]);
magnitude
=
sqrtf
(
tx
*
tx
+
ty
*
ty
);
if
(
magnitude
>
r
[
j
*
width
+
i
])
{
r
[
j
*
width
+
i
]
=
tmp
;
c
=
kk
;
r
[
j
*
width
+
i
]
=
magnitude
;
c
=
ch
;
x
=
tx
;
y
=
ty
;
}
}
/*for(kk = 1; kk < channels; kk++)*/
}
/*for(ch = 1; ch < numChannels; ch++)*/
max
=
boundary_x
[
0
]
*
x
+
boundary_y
[
0
]
*
y
;
max
=
boundary_x
[
0
]
*
x
+
boundary_y
[
0
]
*
y
;
maxi
=
0
;
for
(
kk
=
0
;
kk
<
CNTPARTION
;
kk
++
)
{
tmp_scal
=
boundary_x
[
kk
]
*
x
+
boundary_y
[
kk
]
*
y
;
if
(
tmp_scal
>
max
)
{
max
=
tmp_scal
;
for
(
kk
=
0
;
kk
<
NUM_SECTOR
;
kk
++
)
{
dotProd
=
boundary_x
[
kk
]
*
x
+
boundary_y
[
kk
]
*
y
;
if
(
dotProd
>
max
)
{
max
=
dotProd
;
maxi
=
kk
;
}
else
if
(
-
tmp_scal
>
max
)
{
max
=
-
tmp_scal
;
maxi
=
kk
+
CNTPARTION
;
}
else
{
if
(
-
dotProd
>
max
)
{
max
=
-
dotProd
;
maxi
=
kk
+
NUM_SECTOR
;
}
}
}
alfa
[
j
*
width
*
2
+
i
*
2
]
=
maxi
%
CNTPARTION
;
alfa
[
j
*
width
*
2
+
i
*
2
]
=
maxi
%
NUM_SECTOR
;
alfa
[
j
*
width
*
2
+
i
*
2
+
1
]
=
maxi
;
}
/*for(i = 0; i < width; i++)*/
}
/*for(j = 0; j < height; j++)*/
//
nearest_x
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
k
);
nearest_y
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
k
);
w
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
k
*
2
));
nearest
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
k
);
w
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
k
*
2
));
for
(
i
=
0
;
i
<
k
/
2
;
i
++
)
{
nearest_x
[
i
]
=
-
1
;
nearest_y
[
i
]
=
-
1
;
nearest
[
i
]
=
-
1
;
}
/*for(i = 0; i < k / 2; i++)*/
for
(
i
=
k
/
2
;
i
<
k
;
i
++
)
{
nearest_x
[
i
]
=
1
;
nearest_y
[
i
]
=
1
;
nearest
[
i
]
=
1
;
}
/*for(i = k / 2; i < k; i++)*/
for
(
j
=
0
;
j
<
k
/
2
;
j
++
)
...
...
@@ -160,44 +170,52 @@ int getFeatureMaps_dp(const IplImage* image,const int k, CvLSVMFeatureMap **map)
//
for
(
i
=
0
;
i
<
sizeY
;
i
++
)
{
for
(
j
=
0
;
j
<
sizeX
;
j
++
)
for
(
j
=
0
;
j
<
sizeX
;
j
++
)
{
for
(
ii
=
0
;
ii
<
k
;
ii
++
)
{
for
(
ii
=
0
;
ii
<
k
;
ii
++
)
for
(
jj
=
0
;
jj
<
k
;
jj
++
)
{
if
((
i
*
k
+
ii
>
0
)
&&
(
i
*
k
+
ii
<
height
-
1
)
&&
(
j
*
k
+
jj
>
0
)
&&
(
j
*
k
+
jj
<
width
-
1
))
{
for
(
jj
=
0
;
jj
<
k
;
jj
++
)
{
if
((
i
*
k
+
ii
>
0
)
&&
(
i
*
k
+
ii
<
height
-
1
)
&&
(
j
*
k
+
jj
>
0
)
&&
(
j
*
k
+
jj
<
width
-
1
))
{
d
=
(
k
*
i
+
ii
)
*
width
+
(
j
*
k
+
jj
);
(
*
map
)
->
Map
[(
i
)
*
strsz
+
(
j
)
*
(
*
map
)
->
p
+
alfa
[
d
*
2
]
]
+=
r
[
d
]
*
w
[
ii
*
2
]
*
w
[
jj
*
2
];
(
*
map
)
->
Map
[(
i
)
*
strsz
+
(
j
)
*
(
*
map
)
->
p
+
alfa
[
d
*
2
+
1
]
+
CNTPARTION
]
+=
r
[
d
]
*
w
[
ii
*
2
]
*
w
[
jj
*
2
];
if
((
i
+
nearest_y
[
ii
]
>=
0
)
&&
(
i
+
nearest_y
[
ii
]
<=
sizeY
-
1
))
{
(
*
map
)
->
Map
[(
i
+
nearest_y
[
ii
])
*
strsz
+
(
j
)
*
(
*
map
)
->
p
+
alfa
[
d
*
2
]
]
+=
r
[
d
]
*
w
[
ii
*
2
+
1
]
*
w
[
jj
*
2
];
(
*
map
)
->
Map
[(
i
+
nearest_y
[
ii
])
*
strsz
+
(
j
)
*
(
*
map
)
->
p
+
alfa
[
d
*
2
+
1
]
+
CNTPARTION
]
+=
r
[
d
]
*
w
[
ii
*
2
+
1
]
*
w
[
jj
*
2
];
}
if
((
j
+
nearest_x
[
jj
]
>=
0
)
&&
(
j
+
nearest_x
[
jj
]
<=
sizeX
-
1
))
{
(
*
map
)
->
Map
[(
i
)
*
strsz
+
(
j
+
nearest_x
[
jj
])
*
(
*
map
)
->
p
+
alfa
[
d
*
2
]
]
+=
r
[
d
]
*
w
[
ii
*
2
]
*
w
[
jj
*
2
+
1
];
(
*
map
)
->
Map
[(
i
)
*
strsz
+
(
j
+
nearest_x
[
jj
])
*
(
*
map
)
->
p
+
alfa
[
d
*
2
+
1
]
+
CNTPARTION
]
+=
r
[
d
]
*
w
[
ii
*
2
]
*
w
[
jj
*
2
+
1
];
}
if
((
i
+
nearest_y
[
ii
]
>=
0
)
&&
(
i
+
nearest_y
[
ii
]
<=
sizeY
-
1
)
&&
(
j
+
nearest_x
[
jj
]
>=
0
)
&&
(
j
+
nearest_x
[
jj
]
<=
sizeX
-
1
))
{
(
*
map
)
->
Map
[(
i
+
nearest_y
[
ii
])
*
strsz
+
(
j
+
nearest_x
[
jj
])
*
(
*
map
)
->
p
+
alfa
[
d
*
2
]
]
+=
r
[
d
]
*
w
[
ii
*
2
+
1
]
*
w
[
jj
*
2
+
1
];
(
*
map
)
->
Map
[(
i
+
nearest_y
[
ii
])
*
strsz
+
(
j
+
nearest_x
[
jj
])
*
(
*
map
)
->
p
+
alfa
[
d
*
2
+
1
]
+
CNTPARTION
]
+=
r
[
d
]
*
w
[
ii
*
2
+
1
]
*
w
[
jj
*
2
+
1
];
}
}
}
/*for(jj = 0; jj < k; jj++)*/
}
/*for(ii = 0; ii < k; ii++)*/
}
/*for(j = 1; j < sizeX - 1; j++)*/
d
=
(
k
*
i
+
ii
)
*
width
+
(
j
*
k
+
jj
);
(
*
map
)
->
map
[
i
*
stringSize
+
j
*
(
*
map
)
->
numFeatures
+
alfa
[
d
*
2
]]
+=
r
[
d
]
*
w
[
ii
*
2
]
*
w
[
jj
*
2
];
(
*
map
)
->
map
[
i
*
stringSize
+
j
*
(
*
map
)
->
numFeatures
+
alfa
[
d
*
2
+
1
]
+
NUM_SECTOR
]
+=
r
[
d
]
*
w
[
ii
*
2
]
*
w
[
jj
*
2
];
if
((
i
+
nearest
[
ii
]
>=
0
)
&&
(
i
+
nearest
[
ii
]
<=
sizeY
-
1
))
{
(
*
map
)
->
map
[(
i
+
nearest
[
ii
])
*
stringSize
+
j
*
(
*
map
)
->
numFeatures
+
alfa
[
d
*
2
]
]
+=
r
[
d
]
*
w
[
ii
*
2
+
1
]
*
w
[
jj
*
2
];
(
*
map
)
->
map
[(
i
+
nearest
[
ii
])
*
stringSize
+
j
*
(
*
map
)
->
numFeatures
+
alfa
[
d
*
2
+
1
]
+
NUM_SECTOR
]
+=
r
[
d
]
*
w
[
ii
*
2
+
1
]
*
w
[
jj
*
2
];
}
if
((
j
+
nearest
[
jj
]
>=
0
)
&&
(
j
+
nearest
[
jj
]
<=
sizeX
-
1
))
{
(
*
map
)
->
map
[
i
*
stringSize
+
(
j
+
nearest
[
jj
])
*
(
*
map
)
->
numFeatures
+
alfa
[
d
*
2
]
]
+=
r
[
d
]
*
w
[
ii
*
2
]
*
w
[
jj
*
2
+
1
];
(
*
map
)
->
map
[
i
*
stringSize
+
(
j
+
nearest
[
jj
])
*
(
*
map
)
->
numFeatures
+
alfa
[
d
*
2
+
1
]
+
NUM_SECTOR
]
+=
r
[
d
]
*
w
[
ii
*
2
]
*
w
[
jj
*
2
+
1
];
}
if
((
i
+
nearest
[
ii
]
>=
0
)
&&
(
i
+
nearest
[
ii
]
<=
sizeY
-
1
)
&&
(
j
+
nearest
[
jj
]
>=
0
)
&&
(
j
+
nearest
[
jj
]
<=
sizeX
-
1
))
{
(
*
map
)
->
map
[(
i
+
nearest
[
ii
])
*
stringSize
+
(
j
+
nearest
[
jj
])
*
(
*
map
)
->
numFeatures
+
alfa
[
d
*
2
]
]
+=
r
[
d
]
*
w
[
ii
*
2
+
1
]
*
w
[
jj
*
2
+
1
];
(
*
map
)
->
map
[(
i
+
nearest
[
ii
])
*
stringSize
+
(
j
+
nearest
[
jj
])
*
(
*
map
)
->
numFeatures
+
alfa
[
d
*
2
+
1
]
+
NUM_SECTOR
]
+=
r
[
d
]
*
w
[
ii
*
2
+
1
]
*
w
[
jj
*
2
+
1
];
}
}
}
/*for(jj = 0; jj < k; jj++)*/
}
/*for(ii = 0; ii < k; ii++)*/
}
/*for(j = 1; j < sizeX - 1; j++)*/
}
/*for(i = 1; i < sizeY - 1; i++)*/
cvReleaseImage
(
&
dx
);
...
...
@@ -205,9 +223,8 @@ int getFeatureMaps_dp(const IplImage* image,const int k, CvLSVMFeatureMap **map)
free
(
w
);
free
(
nearest_x
);
free
(
nearest_y
);
free
(
nearest
);
free
(
r
);
free
(
alfa
);
...
...
@@ -218,7 +235,7 @@ int getFeatureMaps_dp(const IplImage* image,const int k, CvLSVMFeatureMap **map)
// Feature map Normalization and Truncation
//
// API
// int normaliz
ationAndTruncationFeatureMaps
(featureMap *map, const float alfa);
// int normaliz
eAndTruncate
(featureMap *map, const float alfa);
// INPUT
// map - feature map
// alfa - truncation threshold
...
...
@@ -227,114 +244,113 @@ int getFeatureMaps_dp(const IplImage* image,const int k, CvLSVMFeatureMap **map)
// RESULT
// Error status
*/
int
normaliz
ationAndTruncationFeatureMaps
(
CvLSVMFeatureMap
*
map
,
const
float
alfa
)
int
normaliz
eAndTruncate
(
CvLSVMFeatureMap
*
map
,
const
float
alfa
)
{
int
i
,
j
,
ii
;
int
sizeX
,
sizeY
,
p
,
pos
,
pp
,
xp
,
pos1
,
pos2
;
float
*
part
_noma
;
// norm of C(i, j)
float
*
new
_d
ata
;
float
norm_val
;
float
*
part
OfNorm
;
// norm of C(i, j)
float
*
new
D
ata
;
float
valOfNorm
;
sizeX
=
map
->
sizeX
;
sizeY
=
map
->
sizeY
;
part
_noma
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
sizeX
*
sizeY
));
part
OfNorm
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
sizeX
*
sizeY
));
p
=
map
->
xp
/
3
;
p
=
NUM_SECTOR
;
xp
=
NUM_SECTOR
*
3
;
pp
=
NUM_SECTOR
*
12
;
for
(
i
=
0
;
i
<
sizeX
*
sizeY
;
i
++
)
{
norm_val
=
0.0
;
pos
=
i
*
map
->
p
;
valOfNorm
=
0.0
f
;
pos
=
i
*
map
->
numFeatures
;
for
(
j
=
0
;
j
<
p
;
j
++
)
{
norm_val
+=
map
->
Map
[
pos
+
j
]
*
map
->
M
ap
[
pos
+
j
];
valOfNorm
+=
map
->
map
[
pos
+
j
]
*
map
->
m
ap
[
pos
+
j
];
}
/*for(j = 0; j < p; j++)*/
part
_noma
[
i
]
=
norm_val
;
part
OfNorm
[
i
]
=
valOfNorm
;
}
/*for(i = 0; i < sizeX * sizeY; i++)*/
xp
=
map
->
xp
;
pp
=
xp
*
4
;
sizeX
-=
2
;
sizeY
-=
2
;
new
_d
ata
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
sizeX
*
sizeY
*
pp
));
new
D
ata
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
sizeX
*
sizeY
*
pp
));
//normalization
for
(
i
=
1
;
i
<=
sizeY
;
i
++
)
{
for
(
j
=
1
;
j
<=
sizeX
;
j
++
)
{
norm_val
=
sqrtf
(
part
_noma
[(
i
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
_noma
[(
i
)
*
(
sizeX
+
2
)
+
(
j
+
1
)]
+
part
_noma
[(
i
+
1
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
_noma
[(
i
+
1
)
*
(
sizeX
+
2
)
+
(
j
+
1
)]);
valOfNorm
=
sqrtf
(
part
OfNorm
[(
i
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
OfNorm
[(
i
)
*
(
sizeX
+
2
)
+
(
j
+
1
)]
+
part
OfNorm
[(
i
+
1
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
OfNorm
[(
i
+
1
)
*
(
sizeX
+
2
)
+
(
j
+
1
)]);
pos1
=
(
i
)
*
(
sizeX
+
2
)
*
xp
+
(
j
)
*
xp
;
pos2
=
(
i
-
1
)
*
(
sizeX
)
*
pp
+
(
j
-
1
)
*
pp
;
for
(
ii
=
0
;
ii
<
p
;
ii
++
)
{
new
_data
[
pos2
+
ii
]
=
map
->
Map
[
pos1
+
ii
]
/
norm_val
;
new
Data
[
pos2
+
ii
]
=
map
->
map
[
pos1
+
ii
]
/
valOfNorm
;
}
/*for(ii = 0; ii < p; ii++)*/
for
(
ii
=
0
;
ii
<
2
*
p
;
ii
++
)
{
new
_data
[
pos2
+
ii
+
p
*
4
]
=
map
->
Map
[
pos1
+
ii
+
p
]
/
norm_val
;
new
Data
[
pos2
+
ii
+
p
*
4
]
=
map
->
map
[
pos1
+
ii
+
p
]
/
valOfNorm
;
}
/*for(ii = 0; ii < 2 * p; ii++)*/
norm_val
=
sqrtf
(
part
_noma
[(
i
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
_noma
[(
i
)
*
(
sizeX
+
2
)
+
(
j
+
1
)]
+
part
_noma
[(
i
-
1
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
_noma
[(
i
-
1
)
*
(
sizeX
+
2
)
+
(
j
+
1
)]);
valOfNorm
=
sqrtf
(
part
OfNorm
[(
i
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
OfNorm
[(
i
)
*
(
sizeX
+
2
)
+
(
j
+
1
)]
+
part
OfNorm
[(
i
-
1
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
OfNorm
[(
i
-
1
)
*
(
sizeX
+
2
)
+
(
j
+
1
)]);
for
(
ii
=
0
;
ii
<
p
;
ii
++
)
{
new
_data
[
pos2
+
ii
+
p
]
=
map
->
Map
[
pos1
+
ii
]
/
norm_val
;
new
Data
[
pos2
+
ii
+
p
]
=
map
->
map
[
pos1
+
ii
]
/
valOfNorm
;
}
/*for(ii = 0; ii < p; ii++)*/
for
(
ii
=
0
;
ii
<
2
*
p
;
ii
++
)
{
new
_data
[
pos2
+
ii
+
p
*
6
]
=
map
->
Map
[
pos1
+
ii
+
p
]
/
norm_val
;
new
Data
[
pos2
+
ii
+
p
*
6
]
=
map
->
map
[
pos1
+
ii
+
p
]
/
valOfNorm
;
}
/*for(ii = 0; ii < 2 * p; ii++)*/
norm_val
=
sqrtf
(
part
_noma
[(
i
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
_noma
[(
i
)
*
(
sizeX
+
2
)
+
(
j
-
1
)]
+
part
_noma
[(
i
+
1
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
_noma
[(
i
+
1
)
*
(
sizeX
+
2
)
+
(
j
-
1
)]);
valOfNorm
=
sqrtf
(
part
OfNorm
[(
i
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
OfNorm
[(
i
)
*
(
sizeX
+
2
)
+
(
j
-
1
)]
+
part
OfNorm
[(
i
+
1
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
OfNorm
[(
i
+
1
)
*
(
sizeX
+
2
)
+
(
j
-
1
)]);
for
(
ii
=
0
;
ii
<
p
;
ii
++
)
{
new
_data
[
pos2
+
ii
+
p
*
2
]
=
map
->
Map
[
pos1
+
ii
]
/
norm_val
;
new
Data
[
pos2
+
ii
+
p
*
2
]
=
map
->
map
[
pos1
+
ii
]
/
valOfNorm
;
}
/*for(ii = 0; ii < p; ii++)*/
for
(
ii
=
0
;
ii
<
2
*
p
;
ii
++
)
{
new
_data
[
pos2
+
ii
+
p
*
8
]
=
map
->
Map
[
pos1
+
ii
+
p
]
/
norm_val
;
new
Data
[
pos2
+
ii
+
p
*
8
]
=
map
->
map
[
pos1
+
ii
+
p
]
/
valOfNorm
;
}
/*for(ii = 0; ii < 2 * p; ii++)*/
norm_val
=
sqrtf
(
part
_noma
[(
i
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
_noma
[(
i
)
*
(
sizeX
+
2
)
+
(
j
-
1
)]
+
part
_noma
[(
i
-
1
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
_noma
[(
i
-
1
)
*
(
sizeX
+
2
)
+
(
j
-
1
)]);
valOfNorm
=
sqrtf
(
part
OfNorm
[(
i
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
OfNorm
[(
i
)
*
(
sizeX
+
2
)
+
(
j
-
1
)]
+
part
OfNorm
[(
i
-
1
)
*
(
sizeX
+
2
)
+
(
j
)]
+
part
OfNorm
[(
i
-
1
)
*
(
sizeX
+
2
)
+
(
j
-
1
)]);
for
(
ii
=
0
;
ii
<
p
;
ii
++
)
{
new
_data
[
pos2
+
ii
+
p
*
3
]
=
map
->
Map
[
pos1
+
ii
]
/
norm_val
;
new
Data
[
pos2
+
ii
+
p
*
3
]
=
map
->
map
[
pos1
+
ii
]
/
valOfNorm
;
}
/*for(ii = 0; ii < p; ii++)*/
for
(
ii
=
0
;
ii
<
2
*
p
;
ii
++
)
{
new
_data
[
pos2
+
ii
+
p
*
10
]
=
map
->
Map
[
pos1
+
ii
+
p
]
/
norm_val
;
new
Data
[
pos2
+
ii
+
p
*
10
]
=
map
->
map
[
pos1
+
ii
+
p
]
/
valOfNorm
;
}
/*for(ii = 0; ii < 2 * p; ii++)*/
}
/*for(j = 1; j <= sizeX; j++)*/
}
/*for(i = 1; i <= sizeY; i++)*/
//truncation
for
(
i
=
0
;
i
<
sizeX
*
sizeY
*
pp
;
i
++
)
{
if
(
new
_data
[
i
]
>
alfa
)
new_d
ata
[
i
]
=
alfa
;
if
(
new
Data
[
i
]
>
alfa
)
newD
ata
[
i
]
=
alfa
;
}
/*for(i = 0; i < sizeX * sizeY * pp; i++)*/
//swop data
map
->
p
=
pp
;
map
->
xp
=
xp
;
map
->
numFeatures
=
pp
;
map
->
sizeX
=
sizeX
;
map
->
sizeY
=
sizeY
;
free
(
map
->
M
ap
);
free
(
part
_noma
);
free
(
map
->
m
ap
);
free
(
part
OfNorm
);
map
->
Map
=
new_d
ata
;
map
->
map
=
newD
ata
;
return
LATENT_SVM_OK
;
}
...
...
@@ -356,21 +372,21 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map)
{
int
i
,
j
,
ii
,
jj
,
k
;
int
sizeX
,
sizeY
,
p
,
pp
,
xp
,
yp
,
pos1
,
pos2
;
float
*
new
_d
ata
;
float
*
new
D
ata
;
float
val
;
float
nx
,
ny
;
sizeX
=
map
->
sizeX
;
sizeY
=
map
->
sizeY
;
p
=
map
->
p
;
pp
=
map
->
xp
+
4
;
p
=
map
->
numFeatures
;
pp
=
NUM_SECTOR
*
3
+
4
;
yp
=
4
;
xp
=
(
map
->
xp
/
3
)
;
xp
=
NUM_SECTOR
;
nx
=
1.0
f
/
sqrtf
((
float
)(
xp
*
2
));
ny
=
1.0
f
/
sqrtf
((
float
)(
yp
));
new
_d
ata
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
sizeX
*
sizeY
*
pp
));
new
D
ata
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
sizeX
*
sizeY
*
pp
));
for
(
i
=
0
;
i
<
sizeY
;
i
++
)
{
...
...
@@ -384,9 +400,9 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map)
val
=
0
;
for
(
ii
=
0
;
ii
<
yp
;
ii
++
)
{
val
+=
map
->
M
ap
[
pos1
+
yp
*
xp
+
ii
*
xp
*
2
+
jj
];
val
+=
map
->
m
ap
[
pos1
+
yp
*
xp
+
ii
*
xp
*
2
+
jj
];
}
/*for(ii = 0; ii < yp; ii++)*/
new
_d
ata
[
pos2
+
k
]
=
val
*
ny
;
new
D
ata
[
pos2
+
k
]
=
val
*
ny
;
k
++
;
}
/*for(jj = 0; jj < xp * 2; jj++)*/
for
(
jj
=
0
;
jj
<
xp
;
jj
++
)
...
...
@@ -394,9 +410,9 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map)
val
=
0
;
for
(
ii
=
0
;
ii
<
yp
;
ii
++
)
{
val
+=
map
->
M
ap
[
pos1
+
ii
*
xp
+
jj
];
val
+=
map
->
m
ap
[
pos1
+
ii
*
xp
+
jj
];
}
/*for(ii = 0; ii < yp; ii++)*/
new
_d
ata
[
pos2
+
k
]
=
val
*
ny
;
new
D
ata
[
pos2
+
k
]
=
val
*
ny
;
k
++
;
}
/*for(jj = 0; jj < xp; jj++)*/
for
(
ii
=
0
;
ii
<
yp
;
ii
++
)
...
...
@@ -404,22 +420,44 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map)
val
=
0
;
for
(
jj
=
0
;
jj
<
2
*
xp
;
jj
++
)
{
val
+=
map
->
M
ap
[
pos1
+
yp
*
xp
+
ii
*
xp
*
2
+
jj
];
val
+=
map
->
m
ap
[
pos1
+
yp
*
xp
+
ii
*
xp
*
2
+
jj
];
}
/*for(jj = 0; jj < xp; jj++)*/
new
_d
ata
[
pos2
+
k
]
=
val
*
nx
;
new
D
ata
[
pos2
+
k
]
=
val
*
nx
;
k
++
;
}
/*for(ii = 0; ii < yp; ii++)*/
}
/*for(j = 0; j < sizeX; j++)*/
}
/*for(i = 0; i < sizeY; i++)*/
//swop data
map
->
p
=
pp
;
map
->
xp
=
pp
;
map
->
numFeatures
=
pp
;
free
(
map
->
map
);
free
(
map
->
Map
);
map
->
map
=
newData
;
return
LATENT_SVM_OK
;
}
map
->
Map
=
new_data
;
int
getPathOfFeaturePyramid
(
IplImage
*
image
,
float
step
,
int
numStep
,
int
startIndex
,
int
sideLength
,
CvLSVMFeaturePyramid
**
maps
)
{
CvLSVMFeatureMap
*
map
;
IplImage
*
scaleTmp
;
float
scale
;
int
i
,
err
;
for
(
i
=
0
;
i
<
numStep
;
i
++
)
{
scale
=
1.0
f
/
powf
(
step
,
(
float
)
i
);
scaleTmp
=
resize_opencv
(
image
,
scale
);
err
=
getFeatureMaps
(
scaleTmp
,
sideLength
,
&
map
);
err
=
normalizeAndTruncate
(
map
,
VAL_OF_TRUNCATE
);
err
=
PCAFeatureMaps
(
map
);
(
*
maps
)
->
pyramid
[
startIndex
+
i
]
=
map
;
cvReleaseImage
(
&
scaleTmp
);
}
/*for(i = 0; i < numStep; i++)*/
return
LATENT_SVM_OK
;
}
...
...
@@ -434,145 +472,52 @@ int PCAFeatureMaps(CvLSVMFeatureMap *map)
const int W, const int H, featurePyramid **maps);
// INPUT
// image - image
// lambda - resize scale
// k - size of cells
// startX - X coordinate of the image rectangle to search
// startY - Y coordinate of the image rectangle to search
// W - width of the image rectangle to search
// H - height of the image rectangle to search
// OUTPUT
// maps - feature maps for all levels
// RESULT
// Error status
*/
int
getFeaturePyramid
(
IplImage
*
image
,
const
int
lambda
,
const
int
k
,
const
int
startX
,
const
int
startY
,
const
int
W
,
const
int
H
,
CvLSVMFeaturePyramid
**
maps
)
int
getFeaturePyramid
(
IplImage
*
image
,
CvLSVMFeaturePyramid
**
maps
)
{
IplImage
*
img2
,
*
imgTmp
,
*
imgResize
;
float
step
,
tmp
;
int
cntStep
;
int
maxcall
;
int
i
;
int
err
;
CvLSVMFeatureMap
*
map
;
IplImage
*
imgResize
;
float
step
;
int
numStep
;
int
maxNumCells
;
int
W
,
H
;
//geting subimage
cvSetImageROI
(
image
,
cvRect
(
startX
,
startY
,
W
,
H
));
img2
=
cvCreateImage
(
cvGetSize
(
image
),
image
->
depth
,
image
->
nChannels
);
cvCopy
(
image
,
img2
,
NULL
);
cvResetImageROI
(
image
);
if
(
img2
->
depth
!=
IPL_DEPTH_32F
)
if
(
image
->
depth
==
IPL_DEPTH_32F
)
{
imgResize
=
cvCreateImage
(
cvSize
(
img2
->
width
,
img2
->
height
)
,
IPL_DEPTH_32F
,
3
);
cvConvert
(
img2
,
imgResize
);
imgResize
=
image
;
}
else
{
imgResize
=
img2
;
imgResize
=
cvCreateImage
(
cvSize
(
image
->
width
,
image
->
height
)
,
IPL_DEPTH_32F
,
3
);
cvConvert
(
image
,
imgResize
);
}
step
=
powf
(
2.0
f
,
1.0
f
/
((
float
)
lambda
));
maxcall
=
W
/
k
;
if
(
maxcall
>
H
/
k
)
{
maxcall
=
H
/
k
;
}
cntStep
=
(
int
)(
logf
((
float
)
maxcall
/
(
5.0
f
))
/
logf
(
step
))
+
1
;
//printf("Count step: %f %d\n", step, cntStep);
W
=
imgResize
->
width
;
H
=
imgResize
->
height
;
allocFeaturePyramidObject
(
maps
,
lambda
,
cntStep
+
lambda
);
for
(
i
=
0
;
i
<
lambda
;
i
++
)
step
=
powf
(
2.0
f
,
1.0
f
/
((
float
)
LAMBDA
)
);
maxNumCells
=
W
/
SIDE_LENGTH
;
if
(
maxNumCells
>
H
/
SIDE_LENGTH
)
{
tmp
=
1.0
f
/
powf
(
step
,
(
float
)
i
);
imgTmp
=
resize_opencv
(
imgResize
,
tmp
);
//imgTmp = resize_article_dp(img2, tmp, 4);
err
=
getFeatureMaps_dp
(
imgTmp
,
4
,
&
map
);
err
=
normalizationAndTruncationFeatureMaps
(
map
,
0.2
f
);
err
=
PCAFeatureMaps
(
map
);
(
*
maps
)
->
pyramid
[
i
]
=
map
;
//printf("%d, %d\n", map->sizeY, map->sizeX);
cvReleaseImage
(
&
imgTmp
);
maxNumCells
=
H
/
SIDE_LENGTH
;
}
numStep
=
(
int
)(
logf
((
float
)
maxNumCells
/
(
5.0
f
))
/
logf
(
step
))
+
1
;
allocFeaturePyramidObject
(
maps
,
numStep
+
LAMBDA
);
/**********************************one**************/
for
(
i
=
0
;
i
<
cntStep
;
i
++
)
{
tmp
=
1.0
f
/
powf
(
step
,
(
float
)
i
);
imgTmp
=
resize_opencv
(
imgResize
,
tmp
);
//imgTmp = resize_article_dp(imgResize, tmp, 8);
err
=
getFeatureMaps_dp
(
imgTmp
,
8
,
&
map
);
err
=
normalizationAndTruncationFeatureMaps
(
map
,
0.2
f
);
err
=
PCAFeatureMaps
(
map
);
(
*
maps
)
->
pyramid
[
i
+
lambda
]
=
map
;
//printf("%d, %d\n", map->sizeY, map->sizeX);
cvReleaseImage
(
&
imgTmp
);
}
/*for(i = 0; i < cntStep; i++)*/
if
(
img2
->
depth
!=
IPL_DEPTH_32F
)
getPathOfFeaturePyramid
(
imgResize
,
step
,
LAMBDA
,
0
,
SIDE_LENGTH
/
2
,
maps
);
getPathOfFeaturePyramid
(
imgResize
,
step
,
numStep
,
LAMBDA
,
SIDE_LENGTH
,
maps
);
if
(
image
->
depth
!=
IPL_DEPTH_32F
)
{
cvReleaseImage
(
&
imgResize
);
}
cvReleaseImage
(
&
img2
);
return
LATENT_SVM_OK
;
}
/*
// add zero border to feature map
//
// API
// int addBordersToFeatureMaps(featureMap *map, const int bX, const int bY);
// INPUT
// map - feature map
// bX - border size in x
// bY - border size in y
// OUTPUT
// map - feature map
// RESULT
// Error status
*/
int
addBordersToFeatureMaps
(
CvLSVMFeatureMap
*
map
,
const
int
bX
,
const
int
bY
){
int
i
,
j
,
jj
;
int
sizeX
,
sizeY
,
p
,
pos1
,
pos2
;
float
*
new_data
;
sizeX
=
map
->
sizeX
;
sizeY
=
map
->
sizeY
;
p
=
map
->
p
;
new_data
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
((
sizeX
+
2
*
bX
)
*
(
sizeY
+
2
*
bY
)
*
p
));
for
(
i
=
0
;
i
<
((
sizeX
+
2
*
bX
)
*
(
sizeY
+
2
*
bY
)
*
p
);
i
++
)
{
new_data
[
i
]
=
(
float
)
0
;
}
/*for(i = 0; i < ((sizeX + 2 * bX) * (sizeY + 2 * bY) * p); i++)*/
for
(
i
=
0
;
i
<
sizeY
;
i
++
)
{
for
(
j
=
0
;
j
<
sizeX
;
j
++
)
{
pos1
=
((
i
)
*
sizeX
+
(
j
))
*
p
;
pos2
=
((
i
+
bY
)
*
(
sizeX
+
2
*
bX
)
+
(
j
+
bX
))
*
p
;
for
(
jj
=
0
;
jj
<
p
;
jj
++
)
{
new_data
[
pos2
+
jj
]
=
map
->
Map
[
pos1
+
jj
];
}
/*for(jj = 0; jj < p; jj++)*/
}
/*for(j = 0; j < sizeX; j++)*/
}
/*for(i = 0; i < sizeY; i++)*/
//swop data
map
->
sizeX
=
sizeX
+
2
*
bX
;
map
->
sizeY
=
sizeY
+
2
*
bY
;
free
(
map
->
Map
);
map
->
Map
=
new_data
;
return
LATENT_SVM_OK
;
}
}
\ No newline at end of file
modules/objdetect/src/latentsvm.cpp
View file @
07eed8c4
...
...
@@ -127,8 +127,7 @@ CvLSVMFeaturePyramid* createFeaturePyramidWithBorder(IplImage *image,
CvLSVMFeaturePyramid
*
H
;
// Obtaining feature pyramid
opResult
=
getFeaturePyramid
(
image
,
LAMBDA
,
SIDE_LENGTH
,
0
,
0
,
image
->
width
,
image
->
height
,
&
H
);
opResult
=
getFeaturePyramid
(
image
,
&
H
);
if
(
opResult
!=
LATENT_SVM_OK
)
{
...
...
@@ -139,7 +138,7 @@ CvLSVMFeaturePyramid* createFeaturePyramidWithBorder(IplImage *image,
// Addition nullable border for each feature map
// the size of the border for root filters
computeBorderSize
(
maxXBorder
,
maxYBorder
,
&
bx
,
&
by
);
for
(
level
=
0
;
level
<
H
->
countLevel
;
level
++
)
for
(
level
=
0
;
level
<
H
->
numLevels
;
level
++
)
{
addNullableBorder
(
H
->
pyramid
[
level
],
bx
,
by
);
}
...
...
@@ -196,7 +195,7 @@ int searchObject(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F
// Transformation filter displacement from the block space
// to the space of pixels at the initial image
// that settles at the level number LAMBDA
convertPoints
(
H
->
countLevel
,
H
->
lambda
,
LAMBDA
,
(
*
points
),
convertPoints
(
H
->
numLevels
,
LAMBDA
,
LAMBDA
,
(
*
points
),
(
*
levels
),
(
*
partsDisplacement
),
(
*
kPoints
),
n
,
maxXBorder
,
maxYBorder
);
...
...
@@ -305,7 +304,7 @@ int searchObjectThreshold(const CvLSVMFeaturePyramid *H,
// Transformation filter displacement from the block space
// to the space of pixels at the initial image
// that settles at the level number LAMBDA
convertPoints
(
H
->
countLevel
,
H
->
lambda
,
LAMBDA
,
(
*
points
),
convertPoints
(
H
->
numLevels
,
LAMBDA
,
LAMBDA
,
(
*
points
),
(
*
levels
),
(
*
partsDisplacement
),
(
*
kPoints
),
n
,
maxXBorder
,
maxYBorder
);
...
...
modules/objdetect/src/lsvmparser.cpp
View file @
07eed8c4
...
...
@@ -658,8 +658,7 @@ void parserModel(FILE * xmlf, CvLSVMFilterObject *** model, int *last, int *max,
if
(
tagVal
==
EMODEL
){
//printf("</Model>\n");
for
(
ii
=
0
;
ii
<=
*
last
;
ii
++
){
(
*
model
)[
ii
]
->
p
=
p
;
(
*
model
)[
ii
]
->
xp
=
9
;
(
*
model
)[
ii
]
->
numFeatures
=
p
;
}
*
count
=
N_comp
;
return
;
...
...
modules/objdetect/src/matching.cpp
View file @
07eed8c4
...
...
@@ -33,7 +33,7 @@ int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float
m1
=
map
->
sizeX
;
n2
=
Fi
->
sizeY
;
m2
=
Fi
->
sizeX
;
p
=
map
->
p
;
p
=
map
->
numFeatures
;
diff1
=
n1
-
n2
+
1
;
diff2
=
m1
-
m2
+
1
;
...
...
@@ -51,7 +51,7 @@ int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float
{
for
(
j2
=
0
;
j2
<
m2
;
j2
++
)
{
pMap
=
map
->
M
ap
+
(
i1
+
i2
)
*
m1
*
p
+
(
j1
+
j2
)
*
p
;
//sm2
pMap
=
map
->
m
ap
+
(
i1
+
i2
)
*
m1
*
p
+
(
j1
+
j2
)
*
p
;
//sm2
pH
=
Fi
->
H
+
(
i2
*
m2
+
j2
)
*
p
;
//sm2
for
(
k
=
0
;
k
<
p
/
4
;
k
++
)
{
...
...
@@ -210,14 +210,14 @@ int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
mapSize
=
mapDimX
*
mapDimY
;
newFilter
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
2
*
mapSize
));
rot2PIFilter
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
filterSize
);
res
=
allocFFTImage
(
image
,
filter
->
p
,
mapDimX
,
mapDimY
);
res
=
allocFFTImage
(
image
,
filter
->
numFeatures
,
mapDimX
,
mapDimY
);
if
(
res
!=
LATENT_SVM_OK
)
{
return
res
;
}
for
(
i
=
0
;
i
<
filter
->
p
;
i
++
)
for
(
i
=
0
;
i
<
filter
->
numFeatures
;
i
++
)
{
rot2PI
(
filter
->
H
,
filter
->
sizeX
,
filter
->
sizeY
,
rot2PIFilter
,
filter
->
p
,
i
);
rot2PI
(
filter
->
H
,
filter
->
sizeX
,
filter
->
sizeY
,
rot2PIFilter
,
filter
->
numFeatures
,
i
);
addNullableBars
(
rot2PIFilter
,
filter
->
sizeX
,
filter
->
sizeY
,
newFilter
,
mapDimX
,
mapDimY
);
fft2d
(
newFilter
,
(
*
image
)
->
channels
[
i
],
mapDimY
,
mapDimX
);
...
...
@@ -241,14 +241,14 @@ int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image)
{
int
i
,
j
,
size
;
float
*
buf
;
allocFFTImage
(
image
,
map
->
p
,
map
->
sizeX
,
map
->
sizeY
);
allocFFTImage
(
image
,
map
->
numFeatures
,
map
->
sizeX
,
map
->
sizeY
);
size
=
map
->
sizeX
*
map
->
sizeY
;
buf
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
2
*
size
));
for
(
i
=
0
;
i
<
map
->
p
;
i
++
)
for
(
i
=
0
;
i
<
map
->
numFeatures
;
i
++
)
{
for
(
j
=
0
;
j
<
size
;
j
++
)
{
buf
[
2
*
j
]
=
map
->
Map
[
j
*
map
->
p
+
i
];
buf
[
2
*
j
]
=
map
->
map
[
j
*
map
->
numFeatures
+
i
];
buf
[
2
*
j
+
1
]
=
0.0
;
}
fft2d
(
buf
,
(
*
image
)
->
channels
[
i
],
map
->
sizeY
,
map
->
sizeX
);
...
...
@@ -282,7 +282,7 @@ int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filt
imagesMultRes
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
size
);
fftImagesMulti
(
featMapImage
->
channels
[
0
],
filterImage
->
channels
[
0
],
featMapImage
->
dimY
,
featMapImage
->
dimX
,
imagesMultRes
);
for
(
i
=
1
;
(
i
<
(
int
)
featMapImage
->
p
)
&&
(
i
<
(
int
)
filterImage
->
p
);
i
++
)
for
(
i
=
1
;
(
i
<
(
int
)
featMapImage
->
numFeatures
)
&&
(
i
<
(
int
)
filterImage
->
numFeatures
);
i
++
)
{
fftImagesMulti
(
featMapImage
->
channels
[
i
],
filterImage
->
channels
[
i
],
featMapImage
->
dimY
,
featMapImage
->
dimX
,
imagesMult
);
...
...
@@ -343,7 +343,7 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap
m1
=
pyramid
->
sizeX
;
n2
=
Fi
->
sizeY
;
m2
=
Fi
->
sizeX
;
p
=
pyramid
->
p
;
p
=
pyramid
->
numFeatures
;
(
*
scoreFi
)
=
NULL
;
(
*
pointsX
)
=
NULL
;
(
*
pointsY
)
=
NULL
;
...
...
@@ -429,7 +429,7 @@ int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage
m1
=
featMapImage
->
dimX
;
n2
=
Fi
->
sizeY
;
m2
=
Fi
->
sizeX
;
p
=
featMapImage
->
p
;
p
=
featMapImage
->
numFeatures
;
(
*
scoreFi
)
=
NULL
;
(
*
pointsX
)
=
NULL
;
(
*
pointsY
)
=
NULL
;
...
...
@@ -525,8 +525,8 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by)
float
*
new_map
;
sizeX
=
map
->
sizeX
+
2
*
bx
;
sizeY
=
map
->
sizeY
+
2
*
by
;
new_map
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
sizeX
*
sizeY
*
map
->
p
);
for
(
i
=
0
;
i
<
sizeX
*
sizeY
*
map
->
p
;
i
++
)
new_map
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
sizeX
*
sizeY
*
map
->
numFeatures
);
for
(
i
=
0
;
i
<
sizeX
*
sizeY
*
map
->
numFeatures
;
i
++
)
{
new_map
[
i
]
=
0.0
;
}
...
...
@@ -534,17 +534,17 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by)
{
for
(
j
=
bx
;
j
<
map
->
sizeX
+
bx
;
j
++
)
{
for
(
k
=
0
;
k
<
map
->
p
;
k
++
)
for
(
k
=
0
;
k
<
map
->
numFeatures
;
k
++
)
{
new_map
[(
i
*
sizeX
+
j
)
*
map
->
p
+
k
]
=
map
->
Map
[((
i
-
by
)
*
map
->
sizeX
+
j
-
bx
)
*
map
->
p
+
k
];
new_map
[(
i
*
sizeX
+
j
)
*
map
->
numFeatures
+
k
]
=
map
->
map
[((
i
-
by
)
*
map
->
sizeX
+
j
-
bx
)
*
map
->
numFeatures
+
k
];
}
}
}
map
->
sizeX
=
sizeX
;
map
->
sizeY
=
sizeY
;
free
(
map
->
M
ap
);
map
->
M
ap
=
new_map
;
free
(
map
->
m
ap
);
map
->
m
ap
=
new_map
;
return
LATENT_SVM_OK
;
}
...
...
@@ -558,19 +558,19 @@ CvLSVMFeatureMap* featureMapBorderPartFilter(CvLSVMFeatureMap *map,
computeBorderSize
(
maxXBorder
,
maxYBorder
,
&
bx
,
&
by
);
sizeX
=
map
->
sizeX
+
2
*
bx
;
sizeY
=
map
->
sizeY
+
2
*
by
;
allocFeatureMapObject
(
&
new_map
,
sizeX
,
sizeY
,
map
->
p
,
map
->
xp
);
for
(
i
=
0
;
i
<
sizeX
*
sizeY
*
map
->
p
;
i
++
)
allocFeatureMapObject
(
&
new_map
,
sizeX
,
sizeY
,
map
->
numFeatures
);
for
(
i
=
0
;
i
<
sizeX
*
sizeY
*
map
->
numFeatures
;
i
++
)
{
new_map
->
Map
[
i
]
=
0.0
;
new_map
->
map
[
i
]
=
0.0
f
;
}
for
(
i
=
by
;
i
<
map
->
sizeY
+
by
;
i
++
)
{
for
(
j
=
bx
;
j
<
map
->
sizeX
+
bx
;
j
++
)
{
for
(
k
=
0
;
k
<
map
->
p
;
k
++
)
for
(
k
=
0
;
k
<
map
->
numFeatures
;
k
++
)
{
new_map
->
Map
[(
i
*
sizeX
+
j
)
*
map
->
p
+
k
]
=
map
->
Map
[((
i
-
by
)
*
map
->
sizeX
+
j
-
bx
)
*
map
->
p
+
k
];
new_map
->
map
[(
i
*
sizeX
+
j
)
*
map
->
numFeatures
+
k
]
=
map
->
map
[((
i
-
by
)
*
map
->
sizeX
+
j
-
bx
)
*
map
->
numFeatures
+
k
];
}
}
}
...
...
@@ -640,7 +640,7 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
dimY
=
H
->
pyramid
[
level
]
->
sizeY
;
// Number of features
p
=
H
->
pyramid
[
level
]
->
p
;
p
=
H
->
pyramid
[
level
]
->
numFeatures
;
// Getting dimension of root filter
nF0
=
all_F
[
0
]
->
sizeY
;
...
...
@@ -888,7 +888,7 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
dimY
=
H
->
pyramid
[
level
]
->
sizeY
;
// Number of features
p
=
H
->
pyramid
[
level
]
->
p
;
p
=
H
->
pyramid
[
level
]
->
numFeatures
;
// Getting dimension of root filter
nF0
=
all_F
[
0
]
->
sizeY
;
...
...
@@ -1109,7 +1109,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// Computation the number of levels for seaching object,
// first lambda-levels are used for computation values
// of score function for each position of root filter
numLevels
=
H
->
countLevel
-
H
->
lambda
;
numLevels
=
H
->
numLevels
-
LAMBDA
;
// Allocation memory for maximum value of score function for each level
tmpScore
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
numLevels
);
...
...
@@ -1135,7 +1135,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
}
// Set current value of the maximum of score function
res
=
maxFunctionalScoreFixedLevel
(
all_F
,
n
,
H
,
H
->
lambda
,
b
,
res
=
maxFunctionalScoreFixedLevel
(
all_F
,
n
,
H
,
LAMBDA
,
b
,
maxXBorder
,
maxYBorder
,
&
(
tmpScore
[
0
]),
tmpPoints
[
0
],
...
...
@@ -1150,9 +1150,9 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
file = fopen("maxScore.csv", "w+");
fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]);
//*/
for
(
l
=
H
->
lambda
+
1
;
l
<
H
->
countLevel
;
l
++
)
for
(
l
=
LAMBDA
+
1
;
l
<
H
->
numLevels
;
l
++
)
{
k
=
l
-
H
->
lambda
;
k
=
l
-
LAMBDA
;
res
=
maxFunctionalScoreFixedLevel
(
all_F
,
n
,
H
,
l
,
b
,
maxXBorder
,
maxYBorder
,
&
(
tmpScore
[
k
]),
...
...
@@ -1191,7 +1191,7 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
if
((
tmpScore
[
i
]
-
maxScore
)
*
(
tmpScore
[
i
]
-
maxScore
)
<=
EPS
)
{
// Computation the number of level
level
=
i
+
H
->
lambda
;
level
=
i
+
LAMBDA
;
// Addition a set of points
f
+=
tmpKPoints
[
i
];
...
...
@@ -1272,7 +1272,7 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// Computation the number of levels for seaching object,
// first lambda-levels are used for computation values
// of score function for each position of root filter
numLevels
=
H
->
countLevel
-
H
->
lambda
;
numLevels
=
H
->
numLevels
-
LAMBDA
;
// Allocation memory for values of score function for each level
// that exceed threshold
...
...
@@ -1305,9 +1305,9 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
fprintf(file, "%i;%lf;\n", H->lambda, tmpScore[0]);
//*/
(
*
kPoints
)
=
0
;
for
(
l
=
H
->
lambda
;
l
<
H
->
countLevel
;
l
++
)
for
(
l
=
LAMBDA
;
l
<
H
->
numLevels
;
l
++
)
{
k
=
l
-
H
->
lambda
;
k
=
l
-
LAMBDA
;
//printf("Score at the level %i\n", l);
res
=
thresholdFunctionalScoreFixedLevel
(
all_F
,
n
,
H
,
l
,
b
,
maxXBorder
,
maxYBorder
,
scoreThreshold
,
...
...
@@ -1339,7 +1339,7 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
for
(
i
=
0
;
i
<
numLevels
;
i
++
)
{
// Computation the number of level
level
=
i
+
H
->
lambda
;
level
=
i
+
LAMBDA
;
// Addition a set of points
f
+=
tmpKPoints
[
i
];
...
...
@@ -1411,7 +1411,7 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all
sumPartFiltersDim
+=
all_F
[
i
]
->
sizeX
*
all_F
[
i
]
->
sizeY
;
}
// Number of levels which are used for computation of score function
numLevels
=
H
->
countLevel
-
H
->
lambda
;
numLevels
=
H
->
numLevels
-
LAMBDA
;
// Allocation memory for saving number of dot products that will be
// computed for each level of feature pyramid
dotProd
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
numLevels
);
...
...
@@ -1421,7 +1421,7 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all
dby
=
2
*
by
;
// Total number of dot products for all levels
numDotProducts
=
0
;
lambda
=
H
->
lambda
;
lambda
=
LAMBDA
;
for
(
i
=
0
;
i
<
numLevels
;
i
++
)
{
dotProd
[
i
]
=
H
->
pyramid
[
i
+
lambda
]
->
sizeX
*
...
...
modules/objdetect/src/routine.cpp
View file @
07eed8c4
#include "precomp.hpp"
#include "_lsvm_routine.h"
int
allocFilterObject
(
CvLSVMFilterObject
**
obj
,
const
int
sizeX
,
const
int
sizeY
,
const
int
p
,
const
int
xp
){
int
allocFilterObject
(
CvLSVMFilterObject
**
obj
,
const
int
sizeX
,
const
int
sizeY
,
const
int
numFeatures
)
{
int
i
;
(
*
obj
)
=
(
CvLSVMFilterObject
*
)
malloc
(
sizeof
(
CvLSVMFilterObject
));
(
*
obj
)
->
sizeX
=
sizeX
;
(
*
obj
)
->
sizeY
=
sizeY
;
(
*
obj
)
->
p
=
p
;
(
*
obj
)
->
xp
=
xp
;
(
*
obj
)
->
sizeX
=
sizeX
;
(
*
obj
)
->
sizeY
=
sizeY
;
(
*
obj
)
->
numFeatures
=
numFeatures
;
(
*
obj
)
->
fineFunction
[
0
]
=
0.0
f
;
(
*
obj
)
->
fineFunction
[
1
]
=
0.0
f
;
(
*
obj
)
->
fineFunction
[
2
]
=
0.0
f
;
...
...
@@ -15,75 +16,87 @@ int allocFilterObject(CvLSVMFilterObject **obj, const int sizeX, const int sizeY
(
*
obj
)
->
V
.
x
=
0
;
(
*
obj
)
->
V
.
y
=
0
;
(
*
obj
)
->
V
.
l
=
0
;
(
*
obj
)
->
H
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
sizeX
*
sizeY
*
p
));
for
(
i
=
0
;
i
<
sizeX
*
sizeY
*
p
;
i
++
){
(
*
obj
)
->
H
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
sizeX
*
sizeY
*
numFeatures
));
for
(
i
=
0
;
i
<
sizeX
*
sizeY
*
numFeatures
;
i
++
)
{
(
*
obj
)
->
H
[
i
]
=
0.0
f
;
}
return
LATENT_SVM_OK
;
}
int
freeFilterObject
(
CvLSVMFilterObject
**
obj
){
if
(
*
obj
==
NULL
)
return
0
;
int
freeFilterObject
(
CvLSVMFilterObject
**
obj
)
{
if
(
*
obj
==
NULL
)
return
LATENT_SVM_MEM_NULL
;
free
((
*
obj
)
->
H
);
free
(
*
obj
);
(
*
obj
)
=
NULL
;
return
LATENT_SVM_OK
;
}
int
allocFeatureMapObject
(
CvLSVMFeatureMap
**
obj
,
const
int
sizeX
,
const
int
sizeY
,
const
int
p
,
const
int
xp
){
int
allocFeatureMapObject
(
CvLSVMFeatureMap
**
obj
,
const
int
sizeX
,
const
int
sizeY
,
const
int
numFeatures
)
{
int
i
;
(
*
obj
)
=
(
CvLSVMFeatureMap
*
)
malloc
(
sizeof
(
CvLSVMFeatureMap
));
(
*
obj
)
->
sizeX
=
sizeX
;
(
*
obj
)
->
sizeY
=
sizeY
;
(
*
obj
)
->
p
=
p
;
(
*
obj
)
->
xp
=
xp
;
(
*
obj
)
->
Map
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
sizeX
*
sizeY
*
p
));
for
(
i
=
0
;
i
<
sizeX
*
sizeY
*
p
;
i
++
){
(
*
obj
)
->
Map
[
i
]
=
0.0
;
(
*
obj
)
->
sizeX
=
sizeX
;
(
*
obj
)
->
sizeY
=
sizeY
;
(
*
obj
)
->
numFeatures
=
numFeatures
;
(
*
obj
)
->
map
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
sizeX
*
sizeY
*
numFeatures
));
for
(
i
=
0
;
i
<
sizeX
*
sizeY
*
numFeatures
;
i
++
)
{
(
*
obj
)
->
map
[
i
]
=
0.0
f
;
}
return
LATENT_SVM_OK
;
}
int
freeFeatureMapObject
(
CvLSVMFeatureMap
**
obj
){
if
(
*
obj
==
NULL
)
return
0
;
free
((
*
obj
)
->
Map
);
int
freeFeatureMapObject
(
CvLSVMFeatureMap
**
obj
)
{
if
(
*
obj
==
NULL
)
return
LATENT_SVM_MEM_NULL
;
free
((
*
obj
)
->
map
);
free
(
*
obj
);
(
*
obj
)
=
NULL
;
return
LATENT_SVM_OK
;
}
int
allocFeaturePyramidObject
(
CvLSVMFeaturePyramid
**
obj
,
const
int
lambda
,
const
int
countLevel
){
int
allocFeaturePyramidObject
(
CvLSVMFeaturePyramid
**
obj
,
const
int
numLevels
)
{
(
*
obj
)
=
(
CvLSVMFeaturePyramid
*
)
malloc
(
sizeof
(
CvLSVMFeaturePyramid
));
(
*
obj
)
->
countLevel
=
countLevel
;
(
*
obj
)
->
pyramid
=
(
CvLSVMFeatureMap
**
)
malloc
(
sizeof
(
CvLSVMFeatureMap
*
)
*
countLevel
);
(
*
obj
)
->
lambda
=
lambda
;
(
*
obj
)
->
numLevels
=
numLevels
;
(
*
obj
)
->
pyramid
=
(
CvLSVMFeatureMap
**
)
malloc
(
sizeof
(
CvLSVMFeatureMap
*
)
*
numLevels
)
;
return
LATENT_SVM_OK
;
}
int
freeFeaturePyramidObject
(
CvLSVMFeaturePyramid
**
obj
){
int
freeFeaturePyramidObject
(
CvLSVMFeaturePyramid
**
obj
)
{
int
i
;
if
(
*
obj
==
NULL
)
return
0
;
for
(
i
=
0
;
i
<
(
*
obj
)
->
countLevel
;
i
++
)
if
(
*
obj
==
NULL
)
return
LATENT_SVM_MEM_NULL
;
for
(
i
=
0
;
i
<
(
*
obj
)
->
numLevels
;
i
++
)
{
freeFeatureMapObject
(
&
((
*
obj
)
->
pyramid
[
i
]));
}
free
((
*
obj
)
->
pyramid
);
free
(
*
obj
);
(
*
obj
)
=
NULL
;
return
LATENT_SVM_OK
;
}
int
allocFFTImage
(
CvLSVMFftImage
**
image
,
int
p
,
int
dimX
,
int
dimY
)
int
allocFFTImage
(
CvLSVMFftImage
**
image
,
int
numFeatures
,
int
dimX
,
int
dimY
)
{
int
i
,
j
,
size
;
*
image
=
(
CvLSVMFftImage
*
)
malloc
(
sizeof
(
CvLSVMFftImage
));
(
*
image
)
->
p
=
p
;
(
*
image
)
->
dimX
=
dimX
;
(
*
image
)
->
dimY
=
dimY
;
(
*
image
)
->
channels
=
(
float
**
)
malloc
(
sizeof
(
float
*
)
*
p
);
(
*
image
)
->
numFeatures
=
numFeatures
;
(
*
image
)
->
dimX
=
dimX
;
(
*
image
)
->
dimY
=
dimY
;
(
*
image
)
->
channels
=
(
float
**
)
malloc
(
sizeof
(
float
*
)
*
numFeatures
);
size
=
2
*
dimX
*
dimY
;
for
(
i
=
0
;
i
<
p
;
i
++
)
for
(
i
=
0
;
i
<
numFeatures
;
i
++
)
{
(
*
image
)
->
channels
[
i
]
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
size
);
for
(
j
=
0
;
j
<
size
;
j
++
)
{
(
*
image
)
->
channels
[
i
][
j
]
=
0.0
;
(
*
image
)
->
channels
[
i
][
j
]
=
0.0
f
;
}
}
return
LATENT_SVM_OK
;
...
...
@@ -91,9 +104,9 @@ int allocFFTImage(CvLSVMFftImage **image, int p, int dimX, int dimY)
int
freeFFTImage
(
CvLSVMFftImage
**
image
)
{
unsigned
i
;
int
i
;
if
(
*
image
==
NULL
)
return
LATENT_SVM_OK
;
for
(
i
=
0
;
i
<
(
*
image
)
->
p
;
i
++
)
for
(
i
=
0
;
i
<
(
*
image
)
->
numFeatures
;
i
++
)
{
free
((
*
image
)
->
channels
[
i
]);
(
*
image
)
->
channels
[
i
]
=
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment