Skip to content

Commit

Permalink
comply to the new ORK API
Browse files Browse the repository at this point in the history
  • Loading branch information
vrabaud committed Jan 17, 2013
1 parent f14cb46 commit a0325f1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 80 deletions.
9 changes: 4 additions & 5 deletions cells/detect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace parts_based_detector
* This class implements the detection cell of the ECTO
* pipeline using the PartsBasedDetector method
*/
struct PartsBasedDetectorCell: public object_recognition_core::db::bases::ModelReaderImpl
struct PartsBasedDetectorCell: public object_recognition_core::db::bases::ModelReaderBase
{
typedef pcl::PointXYZ PointType;
typedef pcl::PointCloud<PointType> PointCloud;
Expand Down Expand Up @@ -97,7 +97,7 @@ struct PartsBasedDetectorCell: public object_recognition_core::db::bases::ModelR
*
* @param db_documents the recognition database documents
*/
void ParameterCallback(const object_recognition_core::db::Documents&)
void parameter_callback(const object_recognition_core::db::Documents&)
{
}

Expand All @@ -112,6 +112,7 @@ struct PartsBasedDetectorCell: public object_recognition_core::db::bases::ModelR
*/
static void declare_params(tendrils& params)
{
object_recognition_core::db::bases::declare_params_impl(params);
params.declare(&PartsBasedDetectorCell::visualize_, "visualize",
"Visualize results", false);
params.declare(&PartsBasedDetectorCell::remove_planes_, "remove_planes",
Expand All @@ -120,8 +121,6 @@ struct PartsBasedDetectorCell: public object_recognition_core::db::bases::ModelR
"The path to the model file").required(true);
params.declare(&PartsBasedDetectorCell::max_overlap_, "max_overlap",
"The maximum overlap allowed between object detections", 0.1);
params.declare(&PartsBasedDetectorCell::object_db_, "db",
"The object db.");
}

/*! @brief declare the I/O of the detector
Expand Down Expand Up @@ -166,7 +165,7 @@ struct PartsBasedDetectorCell: public object_recognition_core::db::bases::ModelR
void configure(const tendrils& params, const tendrils& inputs,
const tendrils& outputs)
{

configure_impl();
std::cout << "MODEL: " << *model_file_ << std::endl;
// create the model object and deserialize it
FileStorageModel model;
Expand Down
19 changes: 10 additions & 9 deletions conf/config_face.by_parts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
source1:
type: ros_kinect
type: RosKinect
module: object_recognition_ros.io
rgb_frame_id: '/camera_rgb_optical_frame'

sink1:
type: 'publisher'
module: 'object_recognition_ros.io'
type: Publisher
module: object_recognition_ros.io

sink2:
type: 'by_parts_publisher'
package: 'object_recognition_by_parts'
type: Publisher
module: 'object_recognition_by_parts'

pipeline1:
type: 'by_parts'
type: PartsBasedDetector
module: 'object_recognition_by_parts'
subtype: 'HOG'
sources: [source1]
sinks: [sink1, sink2]
submethod: 'HOG'
inputs: [source1]
outputs: [sink1, sink2]
parameters:
db:
type: 'CouchDB'
Expand Down
18 changes: 9 additions & 9 deletions conf/config_person.by_parts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
source1:
type: ros_kinect
type: RosKinect
module: 'object_recognition_ros.io'
rgb_frame_id: '/camera_rgb_optical_frame'

sink1:
type: 'publisher'
type: Publisher
module: 'object_recognition_ros.io'

sink2:
type: 'by_parts_publisher'
package: 'object_recognition_by_parts'
type: Publisher
module: 'object_recognition_by_parts'

pipeline1:
type: 'by_parts'
type: PartsBasedDetector
module: 'object_recognition_by_parts'
subtype: 'HOG'
sources: [source1]
sinks: [sink1, sink2]
parameters:
db:
type: 'CouchDB'
root: 'http://bwl:5984'
collection: 'object_recognition'

type: CouchDB
root: http://bwl:5984
collection: object_recognition
# The list of object_ids to analyze
#object_ids: "all"
object_ids: ['1acfa3a425f5637f958c0eaff31fe42d']
Expand Down
4 changes: 2 additions & 2 deletions python/object_recognition_by_parts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#from .trainer import *
from .detector import PartsBasedDetectionPipeline
from .publisher import PublisherSink
from .detector import PartsBasedDetector
from .publisher import Publisher
42 changes: 4 additions & 38 deletions python/object_recognition_by_parts/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

from object_recognition_core.db import ObjectDb, Models
from object_recognition_core.pipelines.detection import DetectionPipeline
from object_recognition_core.pipelines.detection import DetectorBase
from object_recognition_core.utils import json_helper
from ecto_image_pipeline.conversion import MatToPointCloudXYZOrganized
from object_recognition_by_parts_cells import Detector
Expand All @@ -13,13 +13,11 @@
import ecto
from ecto import BlackBoxCellInfo as CellInfo, BlackBoxForward as Forward

class PBDDetector(ecto.BlackBox):
class PartsBasedDetector(ecto.BlackBox, DetectorBase):

def __init__(self, object_db, object_ids, visualize, *args, **kwargs):
self.object_db = object_db
self.object_ids = object_ids
self.visualize = visualize
def __init__(self, *args, **kwargs):
ecto.BlackBox.__init__(self, *args, **kwargs)
DetectorBase.__init__(self)

def declare_cells(self, _p):
return {'detector': CellInfo(Detector), 'mat_to_cloud': MatToPointCloudXYZOrganized()}
Expand All @@ -34,35 +32,3 @@ def declare_forwards(self, _p):

def connections(self, _p):
return [ self.mat_to_cloud['point_cloud'] >> self.detector['input_cloud'] ]


#####################################################################################################################

class PartsBasedDetectionPipeline(DetectionPipeline):

@classmethod
def config_doc(cls):
return """
# The subtype can be any YAML that will help differentiate
# between TOD methods: we usually use the descriptor name
# but anything like parameters could be used
subtype:
type: ""
# TOD requires several parameters
parameters:
# TODO
"""

@classmethod
def type_name(cls):
return 'by_parts'

@classmethod
def detector(self, *args, **kwargs):
visualize = kwargs.pop('visualize', False)
submethod = kwargs.pop('subtype')
parameters = kwargs.pop('parameters')
object_ids = parameters['object_ids']
object_db = ObjectDb(parameters['db'])
model_documents = Models(object_db, object_ids, self.type_name(), json_helper.dict_to_cpp_json_str(submethod))
return PBDDetector(object_db, object_ids, visualize, *args, **parameters['extra'])
18 changes: 5 additions & 13 deletions python/object_recognition_by_parts/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ecto_ros import Mat2Image
from ecto_ros.ecto_sensor_msgs import Publisher_Image
from object_recognition_core.io.sink import Sink
from object_recognition_core.io.sink import SinkBase
import ecto
from ecto import BlackBoxForward as Forward

Expand All @@ -14,6 +14,10 @@ class Publisher(ecto.BlackBox):
"""
Class publishing some outputs from the part based detection
"""
def __init__(self, *args, **kwargs):
ecto.BlackBox.__init__(self, *args, **kwargs)
#SinkBase.__init__(self)

def declare_cells(self, p):
return {'image_converter': Mat2Image(swap_rgb=False)}

Expand All @@ -27,15 +31,3 @@ def connections(self, _p):
connections = [self.image_converter['image'] >> self.image_publisher['input'] ]

return connections

########################################################################################################################

class PublisherSink(Sink):

@classmethod
def type_name(cls):
return 'by_parts_publisher'

@classmethod
def sink(self, *args, **kwargs):
return Publisher()
8 changes: 4 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
find_package(object_recognition_core QUIET)
if (object_recognition_core_FOUND)
enable_testing()
object_recognition_core_detection_test(${CMAKE_CURRENT_SOURCE_DIR}/../conf/config_face.by_parts)
object_recognition_core_detection_test(${CMAKE_CURRENT_SOURCE_DIR}/../conf/config_person.by_parts)
#object_recognition_core_training_test(${CMAKE_CURRENT_SOURCE_DIR}/../conf/config_training.by_parts)
object_recognition_core_config_test(${CMAKE_CURRENT_SOURCE_DIR}/../conf/config_face.by_parts)
object_recognition_core_config_test(${CMAKE_CURRENT_SOURCE_DIR}/../conf/config_person.by_parts)
#object_recognition_core_config_test(${CMAKE_CURRENT_SOURCE_DIR}/../conf/config_training.by_parts)
# publisher tests
object_recognition_core_sink_test(by_parts_publisher "object_recognition_by_parts" "{}")
#object_recognition_core_sink_test(Publisher "object_recognition_by_parts" "{}")
endif()

0 comments on commit a0325f1

Please sign in to comment.