qrcode/detector.cpp
Go to the documentation of this file.
1 #include "detector.h"
2 
3 namespace detectors{
4 namespace qrcode{
6  // configure the reader
7  scanner_.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
8  }
9 
10  bool Detector::detect(cv::Mat& image, int timeout, unsigned int offsetx, unsigned int offsety){
11  bool detected = false;
12  lines_.clear();
13  message_.clear();
14  polygon_.clear();
15 
16  scanner_.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
17  int width = image.cols;
18  int height = image.rows;
19 
20  cv::Mat gray_image;
21  cv::cvtColor(image,gray_image,CV_BGR2GRAY);
22 
23  // wrap image data
24  zbar::Image img(width, height, "Y800", gray_image.data, width * height);
25 
26  // scan the image for barcodes
27  int n = scanner_.scan(img);
28 
29  // extract results
30  for(zbar::Image::SymbolIterator symbol = img.symbol_begin();
31  symbol != img.symbol_end();
32  ++symbol) {
33  message_ = symbol->get_data();
34  detected = true;
35 
36  for(int i=0;
37  i<symbol->get_location_size();
38  i++
39  ){
40 
41  polygon_.push_back(cv::Point(symbol->get_location_x(i) + offsetx,symbol->get_location_y(i) + offsety));
42 
43 
44  }
45 
46  lines_.push_back(std::pair<cv::Point, cv::Point>(cv::Point(polygon_[0].x, polygon_[0].y), cv::Point(polygon_[1].x,
47  polygon_[1].y)));
48  lines_.push_back(std::pair<cv::Point, cv::Point>(cv::Point(polygon_[1].x, polygon_[1].y), cv::Point(polygon_[2].x,
49  polygon_[2].y)));
50  lines_.push_back(std::pair<cv::Point, cv::Point>(cv::Point(polygon_[2].x, polygon_[2].y), cv::Point(polygon_[3].x,
51  polygon_[3].y)));
52  lines_.push_back(std::pair<cv::Point, cv::Point>(cv::Point(polygon_[3].x, polygon_[3].y), cv::Point(polygon_[0].x,
53  polygon_[0].y)));
54 
55 
56  }
57 
58  // clean up
59  img.set_data(NULL, 0);
60 
61  return detected;
62  }
63 }
64 }
bool detect(cv::Mat &image, int timeout=1000, unsigned int offsetx=0, unsigned int offsety=0)
zbar::ImageScanner scanner_
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE const tfScalar & x() const
std::vector< cv::Point > polygon_
Definition: detector_base.h:13
std::vector< std::pair< cv::Point, cv::Point > > lines_
Definition: detector_base.h:12


visp_auto_tracker
Author(s): Filip Novotny
autogenerated on Sat Mar 13 2021 03:20:08