Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.ip.flandmark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.ip.flandmark
Commits
f70e3796
Commit
f70e3796
authored
12 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
Final fixes to landmark detector
parent
2807b257
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
flandmark/ext/ext.cpp
+10
-15
10 additions, 15 deletions
flandmark/ext/ext.cpp
with
10 additions
and
15 deletions
flandmark/ext/ext.cpp
+
10
−
15
View file @
f70e3796
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include
<boost/shared_ptr.hpp>
#include
<boost/shared_ptr.hpp>
#include
<boost/shared_array.hpp>
#include
<boost/shared_array.hpp>
#include
<boost/python.hpp>
#include
<boost/python.hpp>
#include
<bob/core/python/gil.h>
#include
<bob/core/python/ndarray.h>
#include
<bob/core/python/ndarray.h>
#include
<cv.h>
#include
<cv.h>
...
@@ -28,6 +29,7 @@ static void delete_image(IplImage* i) {
...
@@ -28,6 +29,7 @@ static void delete_image(IplImage* i) {
}
}
static
void
delete_storage
(
CvMemStorage
*
s
)
{
static
void
delete_storage
(
CvMemStorage
*
s
)
{
cvClearMemStorage
(
s
);
cvReleaseMemStorage
(
&
s
);
cvReleaseMemStorage
(
&
s
);
}
}
...
@@ -46,8 +48,8 @@ class Localizer {
...
@@ -46,8 +48,8 @@ class Localizer {
Localizer
(
const
std
::
string
&
opencv_cascade
,
Localizer
(
const
std
::
string
&
opencv_cascade
,
const
std
::
string
&
flandmark_model
)
:
const
std
::
string
&
flandmark_model
)
:
m_cascade
((
CvHaarClassifierCascade
*
)
cvLoad
(
opencv_cascade
.
c_str
(),
0
,
0
,
0
),
std
::
ptr_fun
(
delete_cascade
)),
m_cascade
((
CvHaarClassifierCascade
*
)
cvLoad
(
opencv_cascade
.
c_str
(),
0
,
0
,
0
),
std
::
ptr_fun
(
delete_cascade
)),
m_flandmark
(
flandmark_init
(
flandmark_model
.
c_str
()),
std
::
ptr_fun
(
delete_flandmark
))
//
,
m_flandmark
(
flandmark_init
(
flandmark_model
.
c_str
()),
std
::
ptr_fun
(
delete_flandmark
)),
//
m_storage(cvCreateMemStorage(0), std::ptr_fun(delete_storage))
m_storage
(
cvCreateMemStorage
(
0
),
std
::
ptr_fun
(
delete_storage
))
{
{
if
(
!
m_cascade
)
{
if
(
!
m_cascade
)
{
PYTHON_ERROR
(
RuntimeError
,
"Couldnt load Face detector '%s'"
,
opencv_cascade
.
c_str
());
PYTHON_ERROR
(
RuntimeError
,
"Couldnt load Face detector '%s'"
,
opencv_cascade
.
c_str
());
...
@@ -64,8 +66,6 @@ class Localizer {
...
@@ -64,8 +66,6 @@ class Localizer {
* Locates the landmarks from an input image
* Locates the landmarks from an input image
*/
*/
tuple
operator
()
(
bob
::
python
::
const_ndarray
input
)
{
tuple
operator
()
(
bob
::
python
::
const_ndarray
input
)
{
//bob::python::no_gil unlock;
//checks type
//checks type
const
bob
::
core
::
array
::
typeinfo
&
type
=
input
.
type
();
const
bob
::
core
::
array
::
typeinfo
&
type
=
input
.
type
();
if
((
type
.
dtype
!=
bob
::
core
::
array
::
t_uint8
)
||
(
type
.
nd
!=
2
))
{
if
((
type
.
dtype
!=
bob
::
core
::
array
::
t_uint8
)
||
(
type
.
nd
!=
2
))
{
...
@@ -74,22 +74,17 @@ class Localizer {
...
@@ -74,22 +74,17 @@ class Localizer {
//converts to IplImage
//converts to IplImage
const
blitz
::
Array
<
uint8_t
,
2
>
bz
=
input
.
bz
<
uint8_t
,
2
>
();
const
blitz
::
Array
<
uint8_t
,
2
>
bz
=
input
.
bz
<
uint8_t
,
2
>
();
boost
::
shared_ptr
<
IplImage
>
ipl_image
(
cvCreateImage
(
cvSize
(
type
.
shape
[
1
],
boost
::
shared_ptr
<
IplImage
>
ipl_image
(
cvCreateImageHeader
(
cvSize
(
type
.
shape
[
1
],
type
.
shape
[
0
]),
IPL_DEPTH_8U
,
1
),
std
::
ptr_fun
(
delete_image
));
type
.
shape
[
0
]),
IPL_DEPTH_8U
,
1
),
std
::
ptr_fun
(
delete_image
));
ipl_image
->
imageData
=
(
char
*
)
bz
.
data
();
char
*
saved_ipl_data
=
ipl_image
->
imageData
;
ipl_image
->
imageData
=
(
char
*
)
bz
.
data
();
//replace
// Flags for OpenCV face detection
// Flags for OpenCV face detection
CvSize
minFeatureSize
=
cvSize
(
40
,
40
);
CvSize
minFeatureSize
=
cvSize
(
40
,
40
);
int
flags
=
CV_HAAR_DO_CANNY_PRUNING
;
int
flags
=
CV_HAAR_DO_CANNY_PRUNING
;
float
search_scale_factor
=
1.1
f
;
float
search_scale_factor
=
1.1
f
;
// Detect all the faces in the greyscale image.
// Detect all the faces in the greyscale image.
boost
::
shared_ptr
<
CvMemStorage
>
m_storage
(
cvCreateMemStorage
(
0
),
std
::
ptr_fun
(
delete_storage
));
cvClearMemStorage
(
m_storage
.
get
());
CvSeq
*
rects
=
cvHaarDetectObjects
(
ipl_image
.
get
(),
m_cascade
.
get
(),
CvSeq
*
rects
=
cvHaarDetectObjects
(
ipl_image
.
get
(),
m_cascade
.
get
(),
m_storage
.
get
(),
search_scale_factor
,
2
,
flags
,
minFeatureSize
);
m_storage
.
get
(),
search_scale_factor
,
2
,
flags
,
minFeatureSize
);
int
nFaces
=
rects
->
total
;
int
nFaces
=
rects
->
total
;
list
retval
;
list
retval
;
...
@@ -116,7 +111,7 @@ class Localizer {
...
@@ -116,7 +111,7 @@ class Localizer {
retval
.
append
(
det
);
retval
.
append
(
det
);
}
}
ipl_image
->
imageData
=
saved_ipl_data
;
ipl_image
->
imageData
=
0
;
return
tuple
(
retval
);
return
tuple
(
retval
);
...
@@ -126,7 +121,7 @@ class Localizer {
...
@@ -126,7 +121,7 @@ class Localizer {
boost
::
shared_ptr
<
CvHaarClassifierCascade
>
m_cascade
;
boost
::
shared_ptr
<
CvHaarClassifierCascade
>
m_cascade
;
boost
::
shared_ptr
<
FLANDMARK_Model
>
m_flandmark
;
boost
::
shared_ptr
<
FLANDMARK_Model
>
m_flandmark
;
//
boost::shared_ptr<CvMemStorage> m_storage;
boost
::
shared_ptr
<
CvMemStorage
>
m_storage
;
boost
::
shared_array
<
float
>
m_landmarks
;
boost
::
shared_array
<
float
>
m_landmarks
;
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment