blob: 096defbf0b11ae2bf94c986164ea7cb413b76c5f [file] [log] [blame]
Brian Silverman5b3e51e2013-03-29 22:53:44 -07001#ifndef VISION_CAMERA_PROCESSOR_H_
2#define VISION_CAMERA_PROCESSOR_H_
Brian Silverman6ae77dd2013-03-29 22:28:08 -07003
4#include <math.h>
5#include <stdio.h>
6#include <stdlib.h>
Brian Silverman5b3e51e2013-03-29 22:53:44 -07007
Brian Silverman6ae77dd2013-03-29 22:28:08 -07008#include <utility>
9#include <vector>
10
11#include "opencv2/imgproc/imgproc.hpp"
12
13// an over described geometric representation of a rectangle
14class FullRect {
Austin Schuh86bec782013-04-04 05:50:52 +000015 public:
16 FullRect();
17 cv::Point2f ur; // upper right
18 cv::Point2f ul; // upper left
19 cv::Point2f br; // bottom right
20 cv::Point2f bl; // bottom_left
21 cv::Point2f centroid; //centroid
Brian Silverman6ae77dd2013-03-29 22:28:08 -070022};
23
24// All data needed once a target is found
25class Target {
26 public:
27 Target(std::vector<cv::Point> new_contour,
28 std::vector<cv::Point> new_raw_contour,
29 FullRect new_rect, int new_weight, bool _is_90);
30 void refineTarget();
31 double getHeight(bool is_90);
32 FullRect rect; // geometric representation of the target
33 std::vector<cv::Point> this_contour; // opencv contour of target
34 std::vector<cv::Point> raw_contour; // opencv contour of target
35 double height; // top target to robot
36 double weight; // confidence in this target
37};
38
39// main class for processing image data. All relavent data should be
40// accessible through this structure.
41class ProcessorData {
42 public:
43 ProcessorData(int width, int height, bool is_90_);
44 ~ProcessorData();
45 void RGBtoHSV(uchar r, uchar g, uchar b,
46 uchar *h, uchar *s, uchar *v);
47 void threshold(uchar* buffer);
48 void getContours();
49 void filterToTargets();
50 void clear();
51 //protected:
52 int img_width; // all images should be this width
53 int img_height; // and this height
54 bool is_90;
55 int buffer_size; // width * height * 3
56 IplImage *grey_image; // thresholded image
57 cv::Mat *grey_mat; // Matrix representaion (just a header)
58 std::vector<std::pair<std::vector<cv::Point>,
59 std::vector<cv::Point> > > contour_pairs;
60 //std::vector<std::vector<cv::Point> > contours; // filtered contours
61 //yystd::vector<std::vector<cv::Point> > raw_contours; //original contours
62 std::vector<cv::Vec4i> hierarchy; // ordering on contours
63 cv::MemStorage g_storage; // opencv storage
64 static const int HIST_SIZE = 20; // dimension of histogram
65 // ie number of scan lines
Brian Silverman8efe23e2013-07-07 23:31:37 -070066 static constexpr double HIST_SIZE_F = 1.0/20.0; // step size
Brian Silverman6ae77dd2013-03-29 22:28:08 -070067 // should be 1/HIST_SIZE
68 double vert_hist[HIST_SIZE]; // desired vertical histogram
69 double horz_hist[HIST_SIZE]; // desired horizontal histogram
70 // defines the minimum dist for a match
Brian Silverman8efe23e2013-07-07 23:31:37 -070071 static constexpr double HIST_MATCH = 1.9;
Brian Silverman6ae77dd2013-03-29 22:28:08 -070072 double calcHistComponent(
73 cv::Point2i start,
74 cv::Point2i end,
75 cv::Mat thresh_img);
76 double checkHistogram(
77 FullRect rect,
78 cv::Mat thresh_img);
79 public:
80 int h1, s1, v1, h2, s2, v2; // HSV min and max
81 // must be public for tuning
82 IplImage * global_display;
83
84 IplImage *src_header_image; // header for main image
85 std::vector<Target> target_list; // list of found targets
86};
87
Brian Silverman5b3e51e2013-03-29 22:53:44 -070088#endif // VISION_CAMERA_PROCESSOR_H_