image_calibration.h
Go to the documentation of this file.
00001 
00008 #include <ros/publisher.h>
00009 #include <ros/subscriber.h>
00010 #include <ros/node_handle.h>
00011 #include <sensor_msgs/Image.h>
00012 #include <cv_bridge/cv_bridge.h>
00013 #include <opencv2/core/core.hpp>
00014 #include <opencv2/imgproc/imgproc.hpp>
00015 #include <opencv2/gpu/gpu.hpp>
00016 #include <fstream>
00017 #include <cstdlib>
00018 #include <ros/ros.h>
00019 #include <cv.h>
00020 #include <opencv2/highgui/highgui.hpp>
00021 
00022 #include <youbot_overhead_vision/markerCoords.h>
00023 #include <youbot_overhead_vision/CalibCameraImg.h>
00024 #include <youbot_overhead_vision/PositionFromCamera.h>
00025 #include "yaml-cpp/yaml.h"
00026 #include "calibTree.h"
00027 
00028 using namespace std;
00029 #define ENCODING "rgb8"
00030 #define FRAME_ID "calibration"
00031 #define CALIB_ACCURACY 10
00032 
00033 //Object Types 
00034 /*
00035  * L= Left  R = Right.  F = Front B = Back
00036  */
00037 
00038 //Calibration Types
00039 #define ROBOT_LEFT_FRONT 0
00040 #define ROBOT_RIGHT_FRONT 1
00041 #define ROBOT_LEFT_BACK 2
00042 #define ROBOT_RIGHT_BACK 3
00043 #define FLOOR 4
00044 #define NOT_SET 5
00045 
00046 //Marker Clusters Definitions
00047 #define MIN_MARKER_PIXELS 6
00048 #define MARKER_CLUSTER_RADIUS 10 
00049 
00050 //Robot bounding box thresholds
00051 #define MIN_BOUND_WIDTH 45
00052 #define MIN_BOUND_LENGTH 77
00053 #define MAX_BOUND_WIDTH 80
00054 #define MAX_BOUND_LENGTH 120
00055 #define DST_BOUND_THRESH 50
00056 
00057 //Extensions beyond markers
00058 #define FRONT_EXTENDED 33
00059 #define RIGHT_EXTENDED 19
00060 #define BACK_EXTENDED 28
00061 #define LEFT_EXTENDED 19
00062 
00063 //Robot Defs For simulated camera
00064 #define SIDE_MARKER_DIST  41
00065 #define FRONT_MARKER_DIST 36
00066 #define DIAG_MARKER_DIST 54
00067 #define MARKER_ACCURACY 8
00068 
00069 //Camera inputs
00070 #define OVERHEAD_NORTH "/logitech_9000_camera1/image_raw"
00071 #define OVERHEAD_SOUTH "/logitech_9000_camera2/image_raw"
00072 
00073 //overlap constants: #Number of rows of pixels that are found in both cameras.
00074 #define SIM_OVERLAP 30
00075 #define REAL_OVERLAP 62
00076 
00077 #define NORTH_CAMERA 1
00078 #define SOUTH_CAMERA 2
00079 #define BOTH_CAMERAS 3
00080 
00081 #define PI 3.14159
00082 
00092 class imageCalibration
00093 {
00094 public:
00095 
00096   // Determines if the simulation or real world is currently being used.
00097   bool useSim;
00098 
00099   int lastFrameMidpointX;
00100   int lastFrameMidpointY;
00101 
00102   //Determines how close to the calibrating colors a pixel must be to be considered that color.
00103   int calibAccuracy;
00104 
00105   //ROS Publisher and Subscribers
00106   ros::Subscriber imgSub1;
00107   ros::Subscriber imgSub2;
00108   ros::ServiceServer service;
00109   ros::Publisher pubImgCal;
00110   ros::Publisher pubRobotPosition;
00111 
00112   //Contains an image representing the walls
00113   cv::Mat roomBoundary;
00114 
00115   //Contains the colors to apply if a pixel matches a certain calibration value.  Format:[CalibrationType][R,G,B]
00116   int colors[6][3];
00117 
00118   //Struct used to contain the position of marker points, separated into different clusters
00119   struct markerPoints
00120   {
00121     int numPoints;
00122     int avgX;
00123     int avgY;
00124     markerPoints *next;
00125     int markerType; //Indicates which marker was found.
00126   };
00127 
00128   //Pointer to the calibTree object, which allows for tree creating/parsing
00129   calibTree * calTree;
00130 
00131   //vector containing all the robot marker points clusters
00132   vector<markerPoints> robotMarkersVect;
00133 
00134   //Stores the cal image
00135   cv_bridge::CvImagePtr output_Img1;
00136   cv_bridge::CvImagePtr output_Img2;
00137 
00138   //raw image updated by the image_raw subscriber
00139   cv_bridge::CvImagePtr raw_Img1;
00140   cv_bridge::CvImagePtr raw_Img2;
00141 
00142   //marks whether or not the image still has to be updated before being analyzed
00143   bool updatedImageFlag;
00144 
00145   int blurringFactor;
00146   int seq_num;
00147 
00148   //This Mat maintains an image with all the known obstacles in the scene.  When the robot is removed by a box in the main image, this image contains what was known to be in the area before the robot entered that area
00149   cv::Mat pastObstImg;
00150 
00154   imageCalibration();
00155 
00156   /*
00157    *   Destructor
00158    */
00159   ~imageCalibration();
00160 
00169   void getCalibration(int calibType, int calibR, int calibB, int calibG);
00170 
00176   void processImage();
00177 
00182   void imageCallback1(const sensor_msgs::ImageConstPtr& image_msg);
00183 
00188   void imageCallback2(const sensor_msgs::ImageConstPtr& image_msg);
00189 
00193   void addClusters(vector<int> *ImageXCoords, vector<int> *ImageYCoords);
00194 
00198   void applyCalib();
00199 
00200   int count;
00209   bool applyCalibToPixel(int index, int calibType, cv_bridge::CvImagePtr image_msg, int camera);
00210 
00220   void addMarkerPoint(int pointX, int pointY, int calibType);
00221 
00232   bool extrapolateMarkers(vector<int> *ImageXCoords, vector<int> *ImageYCoords);
00233 
00241   void removeRobot(vector<int> xCoords, vector<int> yCoords, int xpos, int ypos);
00242 
00250   vector<cv::RotatedRect> findBoundingBox(cv::Mat image, int xpos, int ypos, int *minDstIndex);
00251 
00257   void applyBoundingBox(cv::Mat *image, cv::RotatedRect rect);
00258 
00262   void resetForNextFrame();
00263 
00269   string convertInt(int number);
00270 
00274   void freerobotVector();
00275 
00276 private:
00277   //File paths for calibration files
00278   string filenames[5];
00279 };


youbot_overhead_vision
Author(s): Fred Clinckemaillie, Maintained by David Kent
autogenerated on Thu Jan 2 2014 12:14:12