Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
e4e374e2
Commit
e4e374e2
authored
Aug 11, 2015
by
Wangyida
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add FindCaffe cmake file for necessary dependency
parent
4483d00c
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
74 additions
and
25 deletions
+74
-25
CMakeLists.txt
modules/cnn_3dobj/CMakeLists.txt
+26
-3
FindCaffe.cmake
modules/cnn_3dobj/FindCaffe.cmake
+14
-0
cnn_3dobj_config.hpp.in
modules/cnn_3dobj/cnn_3dobj_config.hpp.in
+5
-0
cnn_3dobj.hpp
modules/cnn_3dobj/include/opencv2/cnn_3dobj.hpp
+13
-9
cnn_3dobj_config.hpp
modules/cnn_3dobj/include/opencv2/cnn_3dobj_config.hpp
+0
-0
classifyIMG_demo.cpp
modules/cnn_3dobj/samples/classifyIMG_demo.cpp
+2
-1
sphereview_3dobj_demo.cpp
modules/cnn_3dobj/samples/sphereview_3dobj_demo.cpp
+1
-0
cnn_feature.cpp
modules/cnn_3dobj/src/cnn_feature.cpp
+12
-12
precomp.hpp
modules/cnn_3dobj/src/precomp.hpp
+1
-0
No files found.
modules/cnn_3dobj/CMakeLists.txt
View file @
e4e374e2
set
(
the_description
"CNN for 3D object recognition and pose estimation including a completed Sphere View on 3D objects"
)
ocv_define_module
(
cnn_3dobj opencv_core opencv_imgproc opencv_viz opencv_highgui caffe protobuf glog OPTIONAL WRAP python
)
target_link_libraries
(
opencv_cnn_3dobj caffe protobuf glog
)
set
(
CMAKE_MODULE_PATH
${
CMAKE_MODULE_PATH
}
${
CMAKE_CURRENT_SOURCE_DIR
}
)
find_package
(
Caffe
)
if
(
Caffe_FOUND
)
message
(
STATUS
"Caffe: YES"
)
set
(
HAVE_CAFFE 1
)
else
()
message
(
STATUS
"Caffe: NO"
)
endif
()
if
(
HAVE_CAFFE
)
configure_file
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/cnn_3dobj_config.hpp.in
${
CMAKE_CURRENT_SOURCE_DIR
}
/include/opencv2/cnn_3dobj_config.hpp @ONLY
)
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
)
if
(
${
Caffe_FOUND
}
)
include_directories
(
${
Caffe_INCLUDE_DIR
}
)
endif
()
set
(
the_description
"CNN for 3D object recognition and pose estimation including a completed Sphere View on 3D objects"
)
ocv_define_module
(
cnn_3dobj opencv_core opencv_imgproc opencv_viz opencv_highgui OPTIONAL WRAP python
)
if
(
${
Caffe_FOUND
}
)
target_link_libraries
(
opencv_cnn_3dobj
${
Caffe_LIBS
}
)
endif
()
endif
()
modules/cnn_3dobj/FindCaffe.cmake
0 → 100644
View file @
e4e374e2
# Caffe package for CNN Triplet training
unset
(
Caffe_FOUND
)
find_path
(
Caffe_INCLUDE_DIR NAMES caffe/caffe.hpp caffe/common.hpp caffe/net.hpp caffe/proto/caffe.pb.h caffe/util/io.hpp caffe/vision_layers.hpp
HINTS
/usr/local/include
)
find_library
(
Caffe_LIBS NAMES caffe
HINTS
/usr/local/lib
)
if
(
Caffe_LIBS AND Caffe_INCLUDE_DIR
)
set
(
Caffe_FOUND 1
)
endif
()
modules/cnn_3dobj/cnn_3dobj_config.hpp.in
0 → 100644
View file @
e4e374e2
#ifndef __OPENCV_CNN_3DOBJ_CONFIG_HPP__
#define __OPENCV_CNN_3DOBJ_CONFIG_HPP__
// HAVE CAFFE
#cmakedefine HAVE_CAFFE
#endif
modules/cnn_3dobj/include/opencv2/cnn_3dobj.hpp
View file @
e4e374e2
...
...
@@ -58,12 +58,16 @@ the use of this software, even if advised of the possibility of such damage.
#include <tr1/memory>
#include <dirent.h>
#define CPU_ONLY
#include "caffe/blob.hpp"
#include "caffe/common.hpp"
#include "caffe/net.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/util/io.hpp"
#include "caffe/vision_layers.hpp"
#ifdef HAVE_CAFFE
#include <caffe/blob.hpp>
#include <caffe/common.hpp>
#include <caffe/net.hpp>
#include <caffe/proto/caffe.pb.h>
#include <caffe/util/io.hpp>
#include <caffe/vision_layers.hpp>
#endif
#include "opencv2/viz/vizcore.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/highgui/highgui_c.h"
...
...
@@ -132,10 +136,10 @@ class CV_EXPORTS_W IcoSphere
};
class
CV_EXPORTS_W
Classification
class
CV_EXPORTS_W
Feature
{
private
:
caffe
::
shared_ptr
<
caffe
::
Net
<
float
>
>
net_
;
caffe
::
Net
<
float
>*
net_
;
cv
::
Size
input_geometry_
;
int
num_channels_
;
cv
::
Mat
mean_
;
...
...
@@ -150,7 +154,7 @@ class CV_EXPORTS_W Classification
/** @brief Convert the input image to the input image format of the network.
*/
public
:
Classification
();
Feature
();
void
list_dir
(
const
char
*
path
,
std
::
vector
<
string
>&
files
,
bool
r
);
/** @brief Get the file name from a root dictionary.
*/
...
...
modules/cnn_3dobj/include/opencv2/cnn_3dobj_config.hpp
0 → 100644
View file @
e4e374e2
modules/cnn_3dobj/samples/classifyIMG_demo.cpp
View file @
e4e374e2
...
...
@@ -32,6 +32,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#define HAVE_CAFFE
#include <opencv2/cnn_3dobj.hpp>
#include <iomanip>
using
namespace
cv
;
...
...
@@ -50,7 +51,7 @@ int main(int argc, char** argv)
"{device | CPU | device}"
"{dev_id | 0 | dev_id}"
;
cv
::
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
"Demo for
Sphere View data gener
ation"
);
parser
.
about
(
"Demo for
object data classification and pose estim
ation"
);
if
(
parser
.
has
(
"help"
))
{
parser
.
printMessage
();
...
...
modules/cnn_3dobj/samples/sphereview_3dobj_demo.cpp
View file @
e4e374e2
...
...
@@ -32,6 +32,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#define HAVE_CAFFE
#include <opencv2/cnn_3dobj.hpp>
#include <opencv2/viz/vizcore.hpp>
#include <iostream>
...
...
modules/cnn_3dobj/src/cnn_
classification
.cpp
→
modules/cnn_3dobj/src/cnn_
feature
.cpp
View file @
e4e374e2
...
...
@@ -6,8 +6,8 @@ namespace cv
{
namespace
cnn_3dobj
{
Classification
::
Classification
(){};
void
Classification
::
list_dir
(
const
char
*
path
,
vector
<
string
>&
files
,
bool
r
)
Feature
::
Feature
(){};
void
Feature
::
list_dir
(
const
char
*
path
,
vector
<
string
>&
files
,
bool
r
)
{
DIR
*
pDir
;
struct
dirent
*
ent
;
...
...
@@ -25,7 +25,7 @@ namespace cnn_3dobj
if
(
r
)
{
sprintf
(
childpath
,
"%s/%s"
,
path
,
ent
->
d_name
);
Classification
::
list_dir
(
childpath
,
files
,
false
);
Feature
::
list_dir
(
childpath
,
files
,
false
);
}
}
else
...
...
@@ -36,7 +36,7 @@ namespace cnn_3dobj
sort
(
files
.
begin
(),
files
.
end
());
};
void
Classification
::
NetSetter
(
const
string
&
model_file
,
const
string
&
trained_file
,
const
string
&
mean_file
,
const
string
&
cpu_only
,
int
device_id
)
void
Feature
::
NetSetter
(
const
string
&
model_file
,
const
string
&
trained_file
,
const
string
&
mean_file
,
const
string
&
cpu_only
,
int
device_id
)
{
if
(
strcmp
(
cpu_only
.
c_str
(),
"CPU"
)
==
0
)
{
...
...
@@ -48,7 +48,7 @@ namespace cnn_3dobj
caffe
::
Caffe
::
SetDevice
(
device_id
);
}
/* Load the network. */
net_
.
reset
(
new
Net
<
float
>
(
model_file
,
TEST
)
);
net_
=
new
Net
<
float
>
(
model_file
,
TEST
);
net_
->
CopyTrainedLayersFrom
(
trained_file
);
CHECK_EQ
(
net_
->
num_inputs
(),
1
)
<<
"Network should have exactly one input."
;
CHECK_EQ
(
net_
->
num_outputs
(),
1
)
<<
"Network should have exactly one output."
;
...
...
@@ -61,14 +61,14 @@ namespace cnn_3dobj
SetMean
(
mean_file
);
};
void
Classification
::
GetLabellist
(
const
std
::
vector
<
string
>&
name_gallery
)
void
Feature
::
GetLabellist
(
const
std
::
vector
<
string
>&
name_gallery
)
{
for
(
unsigned
int
i
=
0
;
i
<
name_gallery
.
size
();
++
i
)
labels_
.
push_back
(
name_gallery
[
i
]);
};
/* Return the indices of the top N values of vector v. */
std
::
vector
<
int
>
Classification
::
Argmax
(
const
std
::
vector
<
float
>&
v
,
int
N
)
std
::
vector
<
int
>
Feature
::
Argmax
(
const
std
::
vector
<
float
>&
v
,
int
N
)
{
std
::
vector
<
std
::
pair
<
float
,
int
>
>
pairs
;
for
(
size_t
i
=
0
;
i
<
v
.
size
();
++
i
)
...
...
@@ -81,7 +81,7 @@ namespace cnn_3dobj
};
//Return the top N predictions.
std
::
vector
<
std
::
pair
<
string
,
float
>
>
Classification
::
Classify
(
const
cv
::
Mat
&
reference
,
const
cv
::
Mat
&
target
,
int
N
)
std
::
vector
<
std
::
pair
<
string
,
float
>
>
Feature
::
Classify
(
const
cv
::
Mat
&
reference
,
const
cv
::
Mat
&
target
,
int
N
)
{
std
::
vector
<
float
>
output
;
for
(
int
i
=
0
;
i
<
reference
.
rows
;
i
++
)
...
...
@@ -102,7 +102,7 @@ namespace cnn_3dobj
};
/* Load the mean file in binaryproto format. */
void
Classification
::
SetMean
(
const
string
&
mean_file
)
void
Feature
::
SetMean
(
const
string
&
mean_file
)
{
BlobProto
blob_proto
;
ReadProtoFromBinaryFileOrDie
(
mean_file
.
c_str
(),
&
blob_proto
);
...
...
@@ -130,7 +130,7 @@ namespace cnn_3dobj
mean_
=
cv
::
Mat
(
input_geometry_
,
mean
.
type
(),
channel_mean
);
};
void
Classification
::
FeatureExtract
(
InputArray
inputimg
,
OutputArray
feature
,
bool
mean_subtract
,
std
::
string
featrue_blob
)
void
Feature
::
FeatureExtract
(
InputArray
inputimg
,
OutputArray
feature
,
bool
mean_subtract
,
std
::
string
featrue_blob
)
{
Blob
<
float
>*
input_layer
=
net_
->
input_blobs
()[
0
];
input_layer
->
Reshape
(
1
,
num_channels_
,
...
...
@@ -183,7 +183,7 @@ namespace cnn_3dobj
* don't need to rely on cudaMemcpy2D. The last preprocessing
* operation will write the separate channels directly to the input
* layer. */
void
Classification
::
WrapInputLayer
(
std
::
vector
<
cv
::
Mat
>*
input_channels
)
void
Feature
::
WrapInputLayer
(
std
::
vector
<
cv
::
Mat
>*
input_channels
)
{
Blob
<
float
>*
input_layer
=
net_
->
input_blobs
()[
0
];
int
width
=
input_layer
->
width
();
...
...
@@ -197,7 +197,7 @@ namespace cnn_3dobj
}
};
void
Classification
::
Preprocess
(
const
cv
::
Mat
&
img
,
void
Feature
::
Preprocess
(
const
cv
::
Mat
&
img
,
std
::
vector
<
cv
::
Mat
>*
input_channels
,
bool
mean_subtract
)
{
/* Convert the input image to the input image format of the network. */
...
...
modules/cnn_3dobj/src/precomp.hpp
View file @
e4e374e2
...
...
@@ -42,6 +42,7 @@ the use of this software, even if advised of the possibility of such damage.
#ifndef __OPENCV_CNN_3DOBJ_PRECOMP_HPP__
#define __OPENCV_CNN_3DOBJ_PRECOMP_HPP__
#include <opencv2/cnn_3dobj_config.hpp>
#include <opencv2/cnn_3dobj.hpp>
#endif
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