12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049 |
- #ifndef __OPENCV_RGBD_HPP__
- #define __OPENCV_RGBD_HPP__
- #ifdef __cplusplus
- #include <opencv2/core.hpp>
- #include <limits>
- namespace cv
- {
- namespace rgbd
- {
-
- CV_EXPORTS
- inline bool
- isValidDepth(const float & depth)
- {
- return !cvIsNaN(depth);
- }
- CV_EXPORTS
- inline bool
- isValidDepth(const double & depth)
- {
- return !cvIsNaN(depth);
- }
- CV_EXPORTS
- inline bool
- isValidDepth(const short int & depth)
- {
- return (depth != std::numeric_limits<short int>::min()) && (depth != std::numeric_limits<short int>::max());
- }
- CV_EXPORTS
- inline bool
- isValidDepth(const unsigned short int & depth)
- {
- return (depth != std::numeric_limits<unsigned short int>::min())
- && (depth != std::numeric_limits<unsigned short int>::max());
- }
- CV_EXPORTS
- inline bool
- isValidDepth(const int & depth)
- {
- return (depth != std::numeric_limits<int>::min()) && (depth != std::numeric_limits<int>::max());
- }
- CV_EXPORTS
- inline bool
- isValidDepth(const unsigned int & depth)
- {
- return (depth != std::numeric_limits<unsigned int>::min()) && (depth != std::numeric_limits<unsigned int>::max());
- }
-
- class CV_EXPORTS RgbdNormals: public Algorithm
- {
- public:
- enum RGBD_NORMALS_METHOD
- {
- RGBD_NORMALS_METHOD_FALS, RGBD_NORMALS_METHOD_LINEMOD, RGBD_NORMALS_METHOD_SRI
- };
- RgbdNormals()
- :
- rows_(0),
- cols_(0),
- depth_(0),
- K_(Mat()),
- window_size_(0),
- method_(RGBD_NORMALS_METHOD_FALS),
- rgbd_normals_impl_(0)
- {
- }
-
- RgbdNormals(int rows, int cols, int depth, InputArray K, int window_size = 5, int method =
- RGBD_NORMALS_METHOD_FALS);
- ~RgbdNormals();
-
- void
- operator()(InputArray points, OutputArray normals) const;
-
- void
- initialize() const;
- int getRows() const
- {
- return rows_;
- }
- void setRows(int val)
- {
- rows_ = val;
- }
- int getCols() const
- {
- return cols_;
- }
- void setCols(int val)
- {
- cols_ = val;
- }
- int getWindowSize() const
- {
- return window_size_;
- }
- void setWindowSize(int val)
- {
- window_size_ = val;
- }
- int getDepth() const
- {
- return depth_;
- }
- void setDepth(int val)
- {
- depth_ = val;
- }
- cv::Mat getK() const
- {
- return K_;
- }
- void setK(const cv::Mat &val)
- {
- K_ = val;
- }
- int getMethod() const
- {
- return method_;
- }
- void setMethod(int val)
- {
- method_ = val;
- }
- protected:
- void
- initialize_normals_impl(int rows, int cols, int depth, const Mat & K, int window_size, int method) const;
- int rows_, cols_, depth_;
- Mat K_;
- int window_size_;
- int method_;
- mutable void* rgbd_normals_impl_;
- };
-
- class CV_EXPORTS DepthCleaner: public Algorithm
- {
- public:
-
- enum DEPTH_CLEANER_METHOD
- {
- DEPTH_CLEANER_NIL
- };
- DepthCleaner()
- :
- depth_(0),
- window_size_(0),
- method_(DEPTH_CLEANER_NIL),
- depth_cleaner_impl_(0)
- {
- }
-
- DepthCleaner(int depth, int window_size = 5, int method = DEPTH_CLEANER_NIL);
- ~DepthCleaner();
-
- void
- operator()(InputArray points, OutputArray depth) const;
-
- void
- initialize() const;
- int getWindowSize() const
- {
- return window_size_;
- }
- void setWindowSize(int val)
- {
- window_size_ = val;
- }
- int getDepth() const
- {
- return depth_;
- }
- void setDepth(int val)
- {
- depth_ = val;
- }
- int getMethod() const
- {
- return method_;
- }
- void setMethod(int val)
- {
- method_ = val;
- }
- protected:
- void
- initialize_cleaner_impl() const;
- int depth_;
- int window_size_;
- int method_;
- mutable void* depth_cleaner_impl_;
- };
-
- CV_EXPORTS
- void
- registerDepth(InputArray unregisteredCameraMatrix, InputArray registeredCameraMatrix, InputArray registeredDistCoeffs,
- InputArray Rt, InputArray unregisteredDepth, const Size& outputImagePlaneSize,
- OutputArray registeredDepth, bool depthDilation=false);
-
- CV_EXPORTS
- void
- depthTo3dSparse(InputArray depth, InputArray in_K, InputArray in_points, OutputArray points3d);
-
- CV_EXPORTS
- void
- depthTo3d(InputArray depth, InputArray K, OutputArray points3d, InputArray mask = noArray());
-
- CV_EXPORTS
- void
- rescaleDepth(InputArray in, int depth, OutputArray out);
-
- class CV_EXPORTS RgbdPlane: public Algorithm
- {
- public:
- enum RGBD_PLANE_METHOD
- {
- RGBD_PLANE_METHOD_DEFAULT
- };
- RgbdPlane(RGBD_PLANE_METHOD method = RGBD_PLANE_METHOD_DEFAULT)
- :
- method_(method),
- block_size_(40),
- min_size_(block_size_*block_size_),
- threshold_(0.01),
- sensor_error_a_(0),
- sensor_error_b_(0),
- sensor_error_c_(0)
- {
- }
-
- void
- operator()(InputArray points3d, InputArray normals, OutputArray mask,
- OutputArray plane_coefficients);
-
- void
- operator()(InputArray points3d, OutputArray mask, OutputArray plane_coefficients);
- int getBlockSize() const
- {
- return block_size_;
- }
- void setBlockSize(int val)
- {
- block_size_ = val;
- }
- int getMinSize() const
- {
- return min_size_;
- }
- void setMinSize(int val)
- {
- min_size_ = val;
- }
- int getMethod() const
- {
- return method_;
- }
- void setMethod(int val)
- {
- method_ = val;
- }
- double getThreshold() const
- {
- return threshold_;
- }
- void setThreshold(double val)
- {
- threshold_ = val;
- }
- double getSensorErrorA() const
- {
- return sensor_error_a_;
- }
- void setSensorErrorA(double val)
- {
- sensor_error_a_ = val;
- }
- double getSensorErrorB() const
- {
- return sensor_error_b_;
- }
- void setSensorErrorB(double val)
- {
- sensor_error_b_ = val;
- }
- double getSensorErrorC() const
- {
- return sensor_error_c_;
- }
- void setSensorErrorC(double val)
- {
- sensor_error_c_ = val;
- }
- private:
-
- int method_;
-
- int block_size_;
-
- int min_size_;
-
- double threshold_;
-
- double sensor_error_a_, sensor_error_b_, sensor_error_c_;
- };
-
- struct CV_EXPORTS RgbdFrame
- {
- RgbdFrame();
- RgbdFrame(const Mat& image, const Mat& depth, const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1);
- virtual ~RgbdFrame();
- virtual void
- release();
- int ID;
- Mat image;
- Mat depth;
- Mat mask;
- Mat normals;
- };
-
- struct CV_EXPORTS OdometryFrame : public RgbdFrame
- {
-
- enum
- {
- CACHE_SRC = 1, CACHE_DST = 2, CACHE_ALL = CACHE_SRC + CACHE_DST
- };
- OdometryFrame();
- OdometryFrame(const Mat& image, const Mat& depth, const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1);
- virtual void
- release();
- void
- releasePyramids();
- std::vector<Mat> pyramidImage;
- std::vector<Mat> pyramidDepth;
- std::vector<Mat> pyramidMask;
- std::vector<Mat> pyramidCloud;
- std::vector<Mat> pyramid_dI_dx;
- std::vector<Mat> pyramid_dI_dy;
- std::vector<Mat> pyramidTexturedMask;
- std::vector<Mat> pyramidNormals;
- std::vector<Mat> pyramidNormalsMask;
- };
-
- class CV_EXPORTS Odometry: public Algorithm
- {
- public:
-
- enum
- {
- ROTATION = 1, TRANSLATION = 2, RIGID_BODY_MOTION = 4
- };
- static inline float
- DEFAULT_MIN_DEPTH()
- {
- return 0.f;
- }
- static inline float
- DEFAULT_MAX_DEPTH()
- {
- return 4.f;
- }
- static inline float
- DEFAULT_MAX_DEPTH_DIFF()
- {
- return 0.07f;
- }
- static inline float
- DEFAULT_MAX_POINTS_PART()
- {
- return 0.07f;
- }
- static inline float
- DEFAULT_MAX_TRANSLATION()
- {
- return 0.15f;
- }
- static inline float
- DEFAULT_MAX_ROTATION()
- {
- return 15;
- }
-
- bool
- compute(const Mat& srcImage, const Mat& srcDepth, const Mat& srcMask, const Mat& dstImage, const Mat& dstDepth,
- const Mat& dstMask, Mat& Rt, const Mat& initRt = Mat()) const;
-
- bool
- compute(Ptr<OdometryFrame>& srcFrame, Ptr<OdometryFrame>& dstFrame, Mat& Rt, const Mat& initRt = Mat()) const;
-
- virtual Size prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType) const;
- static Ptr<Odometry> create(const String & odometryType);
-
- virtual cv::Mat getCameraMatrix() const = 0;
-
- virtual void setCameraMatrix(const cv::Mat &val) = 0;
-
- virtual int getTransformType() const = 0;
-
- virtual void setTransformType(int val) = 0;
- protected:
- virtual void
- checkParams() const = 0;
- virtual bool
- computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, Mat& Rt,
- const Mat& initRt) const = 0;
- };
-
- class CV_EXPORTS RgbdOdometry: public Odometry
- {
- public:
- RgbdOdometry();
-
- RgbdOdometry(const Mat& cameraMatrix, float minDepth = DEFAULT_MIN_DEPTH(), float maxDepth = DEFAULT_MAX_DEPTH(),
- float maxDepthDiff = DEFAULT_MAX_DEPTH_DIFF(), const std::vector<int>& iterCounts = std::vector<int>(),
- const std::vector<float>& minGradientMagnitudes = std::vector<float>(), float maxPointsPart = DEFAULT_MAX_POINTS_PART(),
- int transformType = RIGID_BODY_MOTION);
- virtual Size prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType) const;
- cv::Mat getCameraMatrix() const
- {
- return cameraMatrix;
- }
- void setCameraMatrix(const cv::Mat &val)
- {
- cameraMatrix = val;
- }
- double getMinDepth() const
- {
- return minDepth;
- }
- void setMinDepth(double val)
- {
- minDepth = val;
- }
- double getMaxDepth() const
- {
- return maxDepth;
- }
- void setMaxDepth(double val)
- {
- maxDepth = val;
- }
- double getMaxDepthDiff() const
- {
- return maxDepthDiff;
- }
- void setMaxDepthDiff(double val)
- {
- maxDepthDiff = val;
- }
- cv::Mat getIterationCounts() const
- {
- return iterCounts;
- }
- void setIterationCounts(const cv::Mat &val)
- {
- iterCounts = val;
- }
- cv::Mat getMinGradientMagnitudes() const
- {
- return minGradientMagnitudes;
- }
- void setMinGradientMagnitudes(const cv::Mat &val)
- {
- minGradientMagnitudes = val;
- }
- double getMaxPointsPart() const
- {
- return maxPointsPart;
- }
- void setMaxPointsPart(double val)
- {
- maxPointsPart = val;
- }
- int getTransformType() const
- {
- return transformType;
- }
- void setTransformType(int val)
- {
- transformType = val;
- }
- double getMaxTranslation() const
- {
- return maxTranslation;
- }
- void setMaxTranslation(double val)
- {
- maxTranslation = val;
- }
- double getMaxRotation() const
- {
- return maxRotation;
- }
- void setMaxRotation(double val)
- {
- maxRotation = val;
- }
- protected:
- virtual void
- checkParams() const;
- virtual bool
- computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, Mat& Rt,
- const Mat& initRt) const;
-
-
- double minDepth, maxDepth, maxDepthDiff;
-
- Mat iterCounts;
-
- Mat minGradientMagnitudes;
- double maxPointsPart;
- Mat cameraMatrix;
- int transformType;
- double maxTranslation, maxRotation;
- };
-
- class ICPOdometry: public Odometry
- {
- public:
- ICPOdometry();
-
- ICPOdometry(const Mat& cameraMatrix, float minDepth = DEFAULT_MIN_DEPTH(), float maxDepth = DEFAULT_MAX_DEPTH(),
- float maxDepthDiff = DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = DEFAULT_MAX_POINTS_PART(),
- const std::vector<int>& iterCounts = std::vector<int>(), int transformType = RIGID_BODY_MOTION);
- virtual Size prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType) const;
- cv::Mat getCameraMatrix() const
- {
- return cameraMatrix;
- }
- void setCameraMatrix(const cv::Mat &val)
- {
- cameraMatrix = val;
- }
- double getMinDepth() const
- {
- return minDepth;
- }
- void setMinDepth(double val)
- {
- minDepth = val;
- }
- double getMaxDepth() const
- {
- return maxDepth;
- }
- void setMaxDepth(double val)
- {
- maxDepth = val;
- }
- double getMaxDepthDiff() const
- {
- return maxDepthDiff;
- }
- void setMaxDepthDiff(double val)
- {
- maxDepthDiff = val;
- }
- cv::Mat getIterationCounts() const
- {
- return iterCounts;
- }
- void setIterationCounts(const cv::Mat &val)
- {
- iterCounts = val;
- }
- double getMaxPointsPart() const
- {
- return maxPointsPart;
- }
- void setMaxPointsPart(double val)
- {
- maxPointsPart = val;
- }
- int getTransformType() const
- {
- return transformType;
- }
- void setTransformType(int val)
- {
- transformType = val;
- }
- double getMaxTranslation() const
- {
- return maxTranslation;
- }
- void setMaxTranslation(double val)
- {
- maxTranslation = val;
- }
- double getMaxRotation() const
- {
- return maxRotation;
- }
- void setMaxRotation(double val)
- {
- maxRotation = val;
- }
- Ptr<RgbdNormals> getNormalsComputer() const
- {
- return normalsComputer;
- }
- protected:
- virtual void
- checkParams() const;
- virtual bool
- computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, Mat& Rt,
- const Mat& initRt) const;
-
-
- double minDepth, maxDepth, maxDepthDiff;
-
- double maxPointsPart;
-
- Mat iterCounts;
- Mat cameraMatrix;
- int transformType;
- double maxTranslation, maxRotation;
- mutable Ptr<RgbdNormals> normalsComputer;
- };
-
- class RgbdICPOdometry: public Odometry
- {
- public:
- RgbdICPOdometry();
-
- RgbdICPOdometry(const Mat& cameraMatrix, float minDepth = DEFAULT_MIN_DEPTH(), float maxDepth = DEFAULT_MAX_DEPTH(),
- float maxDepthDiff = DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = DEFAULT_MAX_POINTS_PART(),
- const std::vector<int>& iterCounts = std::vector<int>(),
- const std::vector<float>& minGradientMagnitudes = std::vector<float>(),
- int transformType = RIGID_BODY_MOTION);
- virtual Size prepareFrameCache(Ptr<OdometryFrame>& frame, int cacheType) const;
- cv::Mat getCameraMatrix() const
- {
- return cameraMatrix;
- }
- void setCameraMatrix(const cv::Mat &val)
- {
- cameraMatrix = val;
- }
- double getMinDepth() const
- {
- return minDepth;
- }
- void setMinDepth(double val)
- {
- minDepth = val;
- }
- double getMaxDepth() const
- {
- return maxDepth;
- }
- void setMaxDepth(double val)
- {
- maxDepth = val;
- }
- double getMaxDepthDiff() const
- {
- return maxDepthDiff;
- }
- void setMaxDepthDiff(double val)
- {
- maxDepthDiff = val;
- }
- double getMaxPointsPart() const
- {
- return maxPointsPart;
- }
- void setMaxPointsPart(double val)
- {
- maxPointsPart = val;
- }
- cv::Mat getIterationCounts() const
- {
- return iterCounts;
- }
- void setIterationCounts(const cv::Mat &val)
- {
- iterCounts = val;
- }
- cv::Mat getMinGradientMagnitudes() const
- {
- return minGradientMagnitudes;
- }
- void setMinGradientMagnitudes(const cv::Mat &val)
- {
- minGradientMagnitudes = val;
- }
- int getTransformType() const
- {
- return transformType;
- }
- void setTransformType(int val)
- {
- transformType = val;
- }
- double getMaxTranslation() const
- {
- return maxTranslation;
- }
- void setMaxTranslation(double val)
- {
- maxTranslation = val;
- }
- double getMaxRotation() const
- {
- return maxRotation;
- }
- void setMaxRotation(double val)
- {
- maxRotation = val;
- }
- Ptr<RgbdNormals> getNormalsComputer() const
- {
- return normalsComputer;
- }
- protected:
- virtual void
- checkParams() const;
- virtual bool
- computeImpl(const Ptr<OdometryFrame>& srcFrame, const Ptr<OdometryFrame>& dstFrame, Mat& Rt,
- const Mat& initRt) const;
-
-
- double minDepth, maxDepth, maxDepthDiff;
-
- double maxPointsPart;
-
- Mat iterCounts;
-
- Mat minGradientMagnitudes;
- Mat cameraMatrix;
- int transformType;
- double maxTranslation, maxRotation;
- mutable Ptr<RgbdNormals> normalsComputer;
- };
-
- CV_EXPORTS
- void
- warpFrame(const Mat& image, const Mat& depth, const Mat& mask, const Mat& Rt, const Mat& cameraMatrix,
- const Mat& distCoeff, Mat& warpedImage, Mat* warpedDepth = 0, Mat* warpedMask = 0);
- }
- }
- #include "opencv2/rgbd/linemod.hpp"
- #endif
- #endif
|