Permalink
Browse files

backport of the cells from SVN, tests passing

  • Loading branch information...
0 parents commit e9a0945e12a2cf18189e7b4958afdd7dffc3c40f @vrabaud vrabaud committed Apr 2, 2012
@@ -0,0 +1,16 @@
+*.orig
+apps/data/
+*.obj
+*.3ds
+*.png
+*.ply
+*.mtl
+*.bag
+build/
+.*
+lib
+bin
+*.pyc
+*.yaml
+*.yml
+*~
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.8)
+project(linemod)
+find_package(catkin REQUIRED)
+catkin_stack()
+catkin_project(linemod
+ DEPENDS OpenCV object_recognition_core
+)
+
+#install targets for all things python
+catkin_python_setup()
+
+set(PYTHON_PACKAGES_PATH gen/py)
+
+# Compile the module
+set_ecto_install_package_name(linemod/ecto_cells)
+
+add_subdirectory(python)
+add_subdirectory(src)
+
+# add the tests
+option(BUILD_TEST "Build tests" ON)
+if(BUILD_TEST)
+ enable_testing()
+ add_subdirectory(test)
+endif()
+
@@ -0,0 +1,24 @@
+# info about the db
+
+source1:
+# type: ros_kinect
+# rgb_frame_id: '/camera_rgb_optical_frame'
+ bag: /home/vrabaud/tod_data_new/training/object_recognition_capture/eggo_01.bag
+
+sink1:
+ type: publisher
+
+pipeline1:
+ method: 'LINEMOD'
+ package: 'linemod'
+ submethod: 'DefaultLINEMOD'
+ sources: [source1]
+ sinks: [sink1]
+ parameters:
+ # The list of object_ids to analyze
+ #object_ids: 'all'
+ object_ids: ['ed149575c2a44c1c095c5bc1b80c3038']
+ db:
+ type: 'CouchDB'
+ root: 'http://localhost:5984'
+ collection: 'object_recognition'
@@ -0,0 +1,11 @@
+pipeline1:
+ method: 'LINEMOD'
+ package: 'linemod'
+ submethod: 'DefaultLINEMOD'
+ parameters:
+ # The list of object_ids to analyze
+ object_ids: 'all'
+ db:
+ type: 'CouchDB'
+ root: 'http://localhost:5984'
+ collection: 'object_recognition'
@@ -0,0 +1,8 @@
+configure_file(__init__.py.plain.in
+ ${ecto_module_PYTHON_OUTPUT}/__init__.py
+ @ONLY
+)
+
+install(FILES ${ecto_module_PYTHON_OUTPUT}/__init__.py
+ DESTINATION ${PYTHON_PACKAGES_PATH}/linemod/ecto_cells
+)
No changes.
@@ -0,0 +1,2 @@
+from detector import *
+from trainer import *
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+"""
+Module defining the LINE-MOD detector to find objects in a scene
+"""
+
+from object_recognition_core.db.object_db import ObjectDb, DbModels, ObjectDbParameters
+from object_recognition_core.utils import json_helper
+from object_recognition_core.pipelines.detection import DetectionPipeline
+import ecto_cells.ecto_linemod as ecto_linemod
+
+########################################################################################################################
+
+class LinemodDetectionPipeline(DetectionPipeline):
+ @classmethod
+ def type_name(cls):
+ return 'LINEMOD'
+
+ def detector(self, *args, **kwargs):
+ #visualize = args.get('visualize', False)
+ submethod = kwargs.get('submethod')
+ parameters = kwargs.get('parameters')
+ object_ids = parameters['object_ids']
+ object_db = ObjectDb(parameters['db'])
+ model_documents = DbModels(object_db, object_ids, self.type_name(), json_helper.dict_to_cpp_json_str(submethod))
+ threshold = parameters.get('threshold', 90)
+ return ecto_linemod.Detector(model_documents=model_documents, db=object_db, threshold=threshold)
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+"""
+Module defining the LINE-MOD trainer to train the LINE-MOD models
+"""
+
+from object_recognition_core.pipelines.training import TrainingPipeline
+from object_recognition_core.utils.json_helper import dict_to_cpp_json_str
+import ecto
+import ecto_cells.ecto_linemod as ecto_linemod
+
+########################################################################################################################
+
+class LinemodTrainingPipeline(TrainingPipeline):
+ '''Implements the training pipeline functions'''
+
+ @classmethod
+ def type_name(cls):
+ return "LINEMOD"
+
+ @classmethod
+ def incremental_model_builder(cls, *args, **kwargs):
+ submethod = kwargs.get('submethod')
+ return ecto_linemod.Trainer(json_submethod=dict_to_cpp_json_str(submethod))
+
+ @classmethod
+ def post_processor(cls, *args, **kwargs):
+ #if not search_params:
+ # raise RuntimeError("You must supply search parameters for TOD.")
+ return ecto_linemod.ModelFiller()
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+from distutils.core import setup
+
+setup(name='LINE-MOD',
+ version='1.0.0',
+ description='A pipeline for object recognition using LINE-MOD from OpenCV',
+ packages=['linemod'],
+ package_dir={'':'python'}
+)
@@ -0,0 +1,23 @@
+find_package(object_recognition_core REQUIRED)
+find_package(OpenCV REQUIRED)
+
+# Compile the ecto
+ectomodule(ecto_linemod
+ db_linemod.cpp
+ linemod_detect.cpp
+ linemod_train.cpp
+ ModelFiller.cpp
+ module.cpp
+)
+
+include_directories(SYSTEM
+ ${OpenCV_INCLUDE_DIRS}
+ ${object_recognition_core_INCLUDE_DIRS}
+)
+
+link_ecto(ecto_linemod
+ ${object_recognition_core_LIBRARIES}
+ ${OpenCV_LIBRARIES}
+)
+
+install_ecto_module(ecto_linemod)
@@ -0,0 +1,40 @@
+#include <ecto/ecto.hpp>
+#include <opencv2/core/core.hpp>
+
+#include <object_recognition_core/common/types.h>
+#include <object_recognition_core/db/db.h>
+
+#include "db_linemod.h"
+
+using object_recognition_core::db::ObjectId;
+using object_recognition_core::db::Document;
+
+namespace linemod_ecto
+{
+ struct ModelFiller
+ {
+ public:
+ static void
+ declare_io(const ecto::tendrils& params, ecto::tendrils& inputs, ecto::tendrils& outputs)
+ {
+ typedef ModelFiller C;
+ inputs.declare(&C::detector_, "detector", "The Linemod detector.").required(true);
+
+ outputs.declare(&C::db_document_, "db_document", "The filled document.");
+ }
+
+ int
+ process(const ecto::tendrils& inputs, const ecto::tendrils& outputs)
+ {
+ db_document_->set_attachment<cv::linemod::Detector>("detector", **detector_);
+ return ecto::OK;
+ }
+
+ private:
+ ecto::spore<cv::Ptr<cv::linemod::Detector> > detector_;
+ ecto::spore<Document> db_document_;
+ };
+}
+
+ECTO_CELL(ecto_linemod, linemod_ecto::ModelFiller, "ModelFiller",
+ "Populates a db document with a TOD model for persisting a later date.")
@@ -0,0 +1,99 @@
+/*
+ * Software License Agreement (BSD License)
+ *
+ * Copyright (c) 2009, Willow Garage, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of Willow Garage, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <boost/filesystem.hpp>
+
+#include <object_recognition_core/db/opencv.h>
+
+#include "db_linemod.h"
+
+namespace
+{
+ object_recognition_core::db::MimeType MIME_TYPE = "text/x-yaml";
+}
+namespace object_recognition
+{
+ namespace db
+ {
+ // Specializations for cv::FileNode
+ template<>
+ void
+ object_recognition_core::db::Document::get_attachment<cv::linemod::Detector>(const AttachmentName &attachment_name,
+ cv::linemod::Detector & value) const
+ {
+ // Get the binary file
+ std::string file_name = temporary_yml_file_name(false);
+ std::stringstream ss;
+ this->get_attachment_stream(attachment_name, ss, MIME_TYPE);
+
+ // Write it to disk
+ std::ofstream writer(file_name.c_str());
+ writer << ss.rdbuf();
+
+ // Read it
+ cv::FileStorage fs(file_name, cv::FileStorage::READ);
+ value.readClass(fs.root(), get_value<ObjectId>("object_id"));
+ boost::filesystem::remove(file_name.c_str());
+ }
+
+ template<>
+ void
+ object_recognition_core::db::Document::get_attachment_and_cache<cv::linemod::Detector>(
+ const AttachmentName &attachment_name, cv::linemod::Detector & value)
+ {
+ }
+
+ template<>
+ void
+ object_recognition_core::db::Document::set_attachment<cv::linemod::Detector>(const AttachmentName &attachment_name,
+ const cv::linemod::Detector & value)
+ {
+ // First write the class to a file
+ std::string file_name = temporary_yml_file_name(false);
+ {
+ cv::FileStorage fs(file_name, cv::FileStorage::WRITE);
+ value.writeClass(value.classIds()[0], fs);
+ }
+
+ // Read the file as a stream
+ std::ifstream reader(file_name.c_str());
+ std::stringstream out;
+ out << reader.rdbuf();
+
+ set_attachment_stream(attachment_name, out, MIME_TYPE);
+ boost::filesystem::remove(file_name.c_str());
+ }
+ }
+}
@@ -0,0 +1,64 @@
+/*
+ * Software License Agreement (BSD License)
+ *
+ * Copyright (c) 2009, Willow Garage, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of Willow Garage, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef DB_LINEMOD_H_
+#define DB_LINEMOD_H_
+
+#include <object_recognition_core/db/db.h>
+#include <opencv2/objdetect/objdetect.hpp>
+
+namespace object_recognition_core
+{
+ namespace db
+ {
+ // Specializations for cv::FileNode
+ template<>
+ void
+ object_recognition_core::db::Document::get_attachment<cv::linemod::Detector>(const AttachmentName &attachment_name,
+ cv::linemod::Detector & value) const;
+
+ template<>
+ void
+ object_recognition_core::db::Document::get_attachment_and_cache<cv::linemod::Detector>(
+ const AttachmentName &attachment_name, cv::linemod::Detector & value);
+
+ template<>
+ void
+ object_recognition_core::db::Document::set_attachment<cv::linemod::Detector>(const AttachmentName &attachment_name,
+ const cv::linemod::Detector & value);
+ }
+}
+
+#endif /* DB_LINEMOD_H_ */
Oops, something went wrong. Retry.

0 comments on commit e9a0945

Please sign in to comment.