TDetector.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002         The MIT License (MIT)
00003 
00004         Copyright (c) <2013> <Vojtech Novak>
00005 
00006         Permission is hereby granted, free of charge, to any person obtaining a copy
00007         of this software and associated documentation files (the "Software"), to deal
00008         in the Software without restriction, including without limitation the rights
00009         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010         copies of the Software, and to permit persons to whom the Software is
00011         furnished to do so, subject to the following conditions:
00012 
00013         The above copyright notice and this permission notice shall be included in
00014         all copies or substantial portions of the Software.
00015 
00016         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022         THE SOFTWARE.
00023 *********************************************************************/
00024 
00025 #include "text_locator/TDetector.hpp"
00026 #include <string>
00027 #include <iostream>
00028 #include <stdio.h>
00029 #include <sstream>
00030 
00031 namespace ros_text_locator {
00032 
00033 TDetector::TDetector() {
00034         params.push_back(ccv_swt_default_params);
00035         ccv_enable_default_cache();
00036 }
00037 
00038 TDetector::TDetector(std::vector<ccv_swt_param_t> params) {
00039         this->params = params;
00040         ccv_enable_default_cache();
00041 }
00042 
00043 TDetector::~TDetector() {
00044 }
00045 
00046 void TDetector::pdetect(ccv_dense_matrix_t* image,
00047                 std::vector<Text2D>& text2d) {
00048         text2d.clear();
00049         //text2d.erase(text2d.begin(), text2d.end());
00050 
00051         if (image != 0) {
00052                 for (int i = 0; i < params.size(); i++) {
00053                         ccv_array_t* words = ccv_swt_detect_words(image, params.at(i));
00054 
00055                         if (words) {
00056                                 text2d.reserve(words->rnum);
00057                                 ccv_rect_t* rect;
00058                                 for (int j = 0; j < words->rnum; j++) {
00059                                         rect = (ccv_rect_t*) ccv_array_get(words, j);
00060                                         //printf("%d %d %d %d\n", rect->x, rect->y, rect->width, rect->height);
00061                                         text2d.push_back(
00062                                                         Text2D(rect->x, rect->y, rect->x + rect->width,
00063                                                                         rect->y + rect->height, ""));
00064                                 }
00065                                 ccv_array_free(words);
00066                         }
00067                 }
00068                 ccv_matrix_free(image);
00069         }
00070 }
00071 
00072 void TDetector::clearParams() {
00073         params.erase(params.begin(), params.end());
00074         params.push_back(ccv_swt_default_params);
00075 }
00076 
00077 void TDetector::detect(const cv::Mat &rgb, std::vector<Text2D>& text2d) {
00078         ccv_dense_matrix_t* image = 0;
00079         ccv_read(rgb.data, &image, CCV_IO_GRAY_RAW | CCV_IO_ANY_RAW | CCV_IO_GRAY,
00080                         rgb.rows, rgb.cols, rgb.step[0]);
00081         TDetector::pdetect(image, text2d);
00082 }
00083 
00084 void TDetector::addParams(ccv_swt_param_t ccv_swt_params) {
00085         params.push_back(ccv_swt_params);
00086 }
00087 
00088 } /* namespace manipulator */
00089 


text_locator
Author(s): Vojtech Novak
autogenerated on Mon Oct 6 2014 07:55:19