Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
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 }
00089