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
00026
00027
00028
00029 #ifndef mrpt_vision_utils_H
00030 #define mrpt_vision_utils_H
00031
00032 #include <mrpt/vision/CFeature.h>
00033 #include <mrpt/utils/CMRPTImage.h>
00034 #include <mrpt/math/utils.h>
00035 #include <mrpt/utils/CLoadableOptions.h>
00036 #include <mrpt/slam/CMetricMap.h>
00037 #include <mrpt/poses/CPose3D.h>
00038 #include <mrpt/poses/CPoint2D.h>
00039 #include <mrpt/poses/CPoint3D.h>
00040
00041 namespace mrpt
00042 {
00043 namespace slam
00044 {
00045 class CLandmarksMap;
00046 class CObservationVisualLandmarks;
00047 }
00048
00051 namespace vision
00052 {
00053 using namespace mrpt::math;
00054 using namespace mrpt::utils;
00055
00056
00057
00058
00061 typedef uint64_t TLandmarkID;
00062
00065 struct MRPTDLLIMPEXP TStereoSystemParams : public mrpt::utils::CLoadableOptions
00066 {
00069 TStereoSystemParams( );
00070
00073 void loadFromConfigFile(
00074 const mrpt::utils::CConfigFileBase &source,
00075 const std::string §ion);
00076
00079 void dumpToTextStream(utils::CStream &out);
00080
00083 enum TUnc_Prop_Method
00084 {
00087 Prop_Linear = -1,
00090 Prop_UT,
00093 Prop_SUT
00094 };
00095
00096 TUnc_Prop_Method uncPropagation;
00097
00100 CMatrix K;
00103 float baseline;
00106 float stdPixel;
00109 float stdDisp;
00112 float maxZ;
00115 float minZ;
00118 float maxY;
00121 float factor_k;
00124 float factor_a;
00127 float factor_b;
00128
00131
00132
00133 };
00134
00136 struct MRPTDLLIMPEXP TPixelCoordf
00137 {
00138 double x,y;
00139 };
00140
00142 struct MRPTDLLIMPEXP TPixelCoord
00143 {
00144 int x,y;
00145 };
00146
00149 struct MRPTDLLIMPEXP TROI
00150 {
00151
00152 TROI();
00153 TROI(float x1, float x2, float y1, float y2, float z1, float z2);
00154
00155
00156 float xMin;
00157 float xMax;
00158 float yMin;
00159 float yMax;
00160 float zMin;
00161 float zMax;
00162 };
00163
00166 struct MRPTDLLIMPEXP TImageROI
00167 {
00168
00169 TImageROI();
00170 TImageROI( float x1, float x2, float y1, float y2 );
00171
00172
00175 float xMin, xMax;
00178 float yMin, yMax;
00179 };
00180
00183 struct MRPTDLLIMPEXP TMatchingOptions : public mrpt::utils::CLoadableOptions
00184 {
00185
00188 enum TMatchingMethod
00189 {
00192 mmCorrelation = 0,
00195 mmDescriptorSIFT,
00198 mmDescriptorSURF
00199 };
00200
00201
00202 TMatchingMethod matching_method;
00203 float epipolar_TH;
00204 float rowCheck_TH;
00205 float ccCheck_TH;
00206
00207
00208 float maxEDD_TH;
00209 float EDD_RATIO;
00210
00211
00212 float minCC_TH;
00213 float minDCC_TH;
00214 float rCC_TH;
00215
00216
00217
00220 TMatchingOptions( );
00221
00224 void loadFromConfigFile(
00225 const mrpt::utils::CConfigFileBase &source,
00226 const std::string §ion);
00227
00230 void dumpToTextStream(utils::CStream &out);
00231
00232 };
00233
00247 void MRPTDLLIMPEXP openCV_cross_correlation(
00248 const CMRPTImage &img,
00249 const CMRPTImage &patch_img,
00250 size_t &x_max,
00251 size_t &y_max,
00252 double &max_val,
00253 int x_search_ini=-1,
00254 int y_search_ini=-1,
00255 int x_search_size=-1,
00256 int y_search_size=-1);
00257
00261 void MRPTDLLIMPEXP flip(CMRPTImage &img);
00262
00270 poses::CPoint3D MRPTDLLIMPEXP pixelTo3D(float x,float y, const CMatrix &A);
00271
00287 CMatrix MRPTDLLIMPEXP buildIntrinsicParamsMatrix(
00288 float focalLengthX,
00289 float focalLengthY,
00290 float centerX,
00291 float centerY);
00292
00337 CMatrix MRPTDLLIMPEXP defaultIntrinsicParamsMatrix(
00338 unsigned int camIndex = 0,
00339 unsigned int resolutionX = 320,
00340 unsigned int resolutionY = 240 );
00341
00345 void MRPTDLLIMPEXP deleteRepeatedFeats( CFeatureList &list );
00346
00364 void MRPTDLLIMPEXP rowChecking( CFeatureList &leftList,
00365 CFeatureList &rightList,
00366 float threshold = 0.0);
00367
00371 void MRPTDLLIMPEXP checkTrackedFeatures( CFeatureList &leftList,
00372 CFeatureList &rightList,
00373 vision::TMatchingOptions options);
00374
00375
00381 void MRPTDLLIMPEXP getDispersion( const CFeatureList &list,
00382 vector_float &std,
00383 vector_float &mean );
00384
00387 void MRPTDLLIMPEXP trackFeatures( const CMRPTImage &inImg1,
00388 const CMRPTImage &inImg2,
00389 vision::CFeatureList &featureList,
00390 const unsigned int &window_width = 7,
00391 const unsigned int &window_height = 7);
00392
00396 void MRPTDLLIMPEXP filterBadCorrsByDistance( mrpt::slam::CMetricMap::TMatchingPairList &list,
00397 unsigned int numberOfSigmas );
00398
00399
00404 void MRPTDLLIMPEXP correctDistortion(
00405 CMRPTImage &in_img,
00406 CMRPTImage &out_img,
00407 CMatrix A,
00408 CMatrix dist_coeffs );
00409
00413 void MRPTDLLIMPEXP hsv2rgb(
00414 float h,
00415 float s,
00416 float v,
00417 float &r,
00418 float &g,
00419 float &b);
00420
00424 void MRPTDLLIMPEXP rgb2hsv(
00425 float r,
00426 float g,
00427 float b,
00428 float &h,
00429 float &s,
00430 float &v );
00431
00435 enum TColormap
00436 {
00437 cmGRAYSCALE = 0,
00438 cmJET
00439 };
00440
00443 void MRPTDLLIMPEXP colormap(
00444 const TColormap &color_map,
00445 const float &color_index,
00446 float &r,
00447 float &g,
00448 float &b);
00449
00453 void MRPTDLLIMPEXP jet2rgb(
00454 const float &color_index,
00455 float &r,
00456 float &g,
00457 float &b);
00458
00463 enum TInterpolationMethod
00464 {
00465 imNEAREST = 0,
00466 imBILINEAR,
00467 imBICUBIC,
00468 imAREA
00469 };
00470
00471
00475 double MRPTDLLIMPEXP computeMsd( const mrpt::slam::CMetricMap::TMatchingPairList &list,
00476 const mrpt::poses::CPose3D &Rt );
00477
00481 void MRPTDLLIMPEXP cloudsToMatchedList( const mrpt::slam::CObservationVisualLandmarks &cloud1,
00482 const mrpt::slam::CObservationVisualLandmarks &cloud2,
00483 mrpt::slam::CMetricMap::TMatchingPairList &outList);
00484
00491 float MRPTDLLIMPEXP computeMainOrientation( const CMRPTImage &image,
00492 const unsigned int &x,
00493 const unsigned int &y );
00494
00501 size_t MRPTDLLIMPEXP matchFeatures( const CFeatureList &list1,
00502 const CFeatureList &list2,
00503 CMatchedFeatureList &matches,
00504 const TMatchingOptions &options = TMatchingOptions() );
00505
00511 void MRPTDLLIMPEXP projectMatchedFeatures(
00512 CMatchedFeatureList &mfList,
00513 const vision::TStereoSystemParams ¶m,
00514 mrpt::slam::CLandmarksMap &landmarks );
00515
00516
00519 struct TImageCalibData
00520 {
00521 CMRPTImage img_original;
00522 CMRPTImage img_checkboard;
00523 CMRPTImage img_rectified;
00524 std::vector<mrpt::poses::CPoint2D> detected_corners;
00525 mrpt::poses::CPose3D reconstructed_camera_pose;
00526 std::vector<TPixelCoordf> projectedPoints_distorted;
00527 std::vector<TPixelCoordf> projectedPoints_undistorted;
00528 };
00529
00533 typedef std::map<std::string,TImageCalibData> TCalibrationImageList;
00534
00547 bool MRPTDLLIMPEXP checkerBoardCameraCalibration(
00548 TCalibrationImageList &images,
00549 unsigned int check_size_x,
00550 unsigned int check_size_y,
00551 double check_squares_length_X_meters,
00552 double check_squares_length_Y_meters,
00553 CMatrixDouble &intrinsicParams,
00554 std::vector<double> &distortionParams,
00555 bool normalize_image = true
00556 );
00557
00558 }
00559 }
00560
00561
00562 #endif