detector.cpp
Go to the documentation of this file.
00001 #include "detector.h"
00002 
00003 namespace detectors{
00004 namespace qrcode{
00005   Detector::Detector(){
00006     // configure the reader
00007     scanner_.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
00008   }
00009 
00010   bool Detector::detect(cv::Mat& image, int timeout, unsigned int offsetx, unsigned int offsety){
00011     bool detected = false;
00012     lines_.clear();
00013     message_.clear();
00014     polygon_.clear();
00015 
00016     scanner_.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
00017     int width = image.cols;
00018     int height = image.rows;
00019 
00020     cv::Mat gray_image;
00021     cv::cvtColor(image,gray_image,CV_BGR2GRAY);
00022 
00023     // wrap image data
00024     zbar::Image img(width, height, "Y800", gray_image.data, width * height);
00025 
00026     // scan the image for barcodes
00027     int n = scanner_.scan(img);
00028 
00029     // extract results
00030     for(zbar::Image::SymbolIterator symbol = img.symbol_begin();
00031         symbol != img.symbol_end();
00032         ++symbol) {
00033         message_ = symbol->get_data();
00034         detected = true;
00035 
00036         for(int i=0;
00037             i<symbol->get_location_size();
00038             i++
00039             ){
00040 
00041             polygon_.push_back(cv::Point(symbol->get_location_x(i) + offsetx,symbol->get_location_y(i) + offsety));
00042 
00043 
00044         }
00045 
00046         lines_.push_back(std::pair<cv::Point, cv::Point>(cv::Point(polygon_[0].x, polygon_[0].y), cv::Point(polygon_[1].x,
00047                                                                                                         polygon_[1].y)));
00048         lines_.push_back(std::pair<cv::Point, cv::Point>(cv::Point(polygon_[1].x, polygon_[1].y), cv::Point(polygon_[2].x,
00049                                                                                                             polygon_[2].y)));
00050         lines_.push_back(std::pair<cv::Point, cv::Point>(cv::Point(polygon_[2].x, polygon_[2].y), cv::Point(polygon_[3].x,
00051                                                                                                             polygon_[3].y)));
00052         lines_.push_back(std::pair<cv::Point, cv::Point>(cv::Point(polygon_[3].x, polygon_[3].y), cv::Point(polygon_[0].x,
00053                                                                                                         polygon_[0].y)));
00054 
00055 
00056     }
00057 
00058     // clean up
00059     img.set_data(NULL, 0);
00060 
00061     return detected;
00062   }
00063 }
00064 }


visp_auto_tracker
Author(s): Filip Novotny
autogenerated on Mon Oct 6 2014 08:40:41