fix: use normalized and real depth in depth sample.

This commit is contained in:
TinyOh 2019-03-26 09:45:06 +08:00
parent d1ebc6cad5
commit a9f0e49a5a
4 changed files with 73 additions and 2 deletions

View File

@ -204,6 +204,15 @@ class MYNTEYE_API API {
* Get the intrinsics base of stream. * Get the intrinsics base of stream.
*/ */
std::shared_ptr<IntrinsicsBase> GetIntrinsicsBase(const Stream &stream) const; std::shared_ptr<IntrinsicsBase> GetIntrinsicsBase(const Stream &stream) const;
/**
* Get the intrinsics of stream.
*/
template <typename T>
T GetDisparityParams() const;
/**
* Get the intrinsics base of stream.
*/
std::shared_ptr<DisparityParamsBase> GetDisparityParamsBase() const;
/** /**
* Get the extrinsics from one stream to another. * Get the extrinsics from one stream to another.
*/ */

View File

@ -626,6 +626,10 @@ struct MYNTEYE_API Extrinsics {
MYNTEYE_API MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const Extrinsics &ex); std::ostream &operator<<(std::ostream &os, const Extrinsics &ex);
/**
* @defgroup disparity params
*/
/** /**
* @ingroup disparity * @ingroup disparity
* Camera disparity computing method type. * Camera disparity computing method type.
@ -639,6 +643,33 @@ enum class DisparityComputingMethod : std::uint8_t {
UNKNOW UNKNOW
}; };
struct MYNTEYE_API DisparityParamsBase {
DisparityParamsBase() {
disparity_model_ = DisparityComputingMethod::UNKNOW;
}
virtual ~DisparityParamsBase() {}
virtual void ResizeIntrinsics() {}
/** The calibration model */
DisparityComputingMethod disparity_model() const {
return disparity_model_;
}
protected:
DisparityComputingMethod disparity_model_;
};
struct MYNTEYE_API DisparityParamsSGBM : public DisparityParamsBase {
DisparityParamsSGBM() {
disparity_model_ = DisparityComputingMethod::SGBM;
}
};
struct MYNTEYE_API DisparityParamsBM : public DisparityParamsBase {
DisparityParamsBM() {
disparity_model_ = DisparityComputingMethod::BM;
}
};
/** /**
* @defgroup datatypes Datatypes * @defgroup datatypes Datatypes

View File

@ -30,11 +30,13 @@ int main(int argc, char *argv[]) {
api->SetDisparityComputingMethodType(DisparityComputingMethod::BM); api->SetDisparityComputingMethodType(DisparityComputingMethod::BM);
api->EnableStreamData(Stream::DEPTH); api->EnableStreamData(Stream::DEPTH);
api->EnableStreamData(Stream::DISPARITY_NORMALIZED);
api->Start(Source::VIDEO_STREAMING); api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame"); cv::namedWindow("frame");
cv::namedWindow("depth"); cv::namedWindow("depth_real");
cv::namedWindow("depth_normalized");
while (true) { while (true) {
api->WaitForStreams(); api->WaitForStreams();
@ -47,9 +49,16 @@ int main(int argc, char *argv[]) {
cv::imshow("frame", img); cv::imshow("frame", img);
} }
// this code is for real depth data
auto &&depth_data = api->GetStreamData(Stream::DEPTH); auto &&depth_data = api->GetStreamData(Stream::DEPTH);
if (!depth_data.frame.empty()) { if (!depth_data.frame.empty()) {
cv::imshow("depth", depth_data.frame); // CV_16UC1 cv::imshow("depth_real", depth_data.frame); // CV_16UC1
}
// this code is for normalized depth data
auto &&disp_norm_data = api->GetStreamData(Stream::DISPARITY_NORMALIZED);
if (!disp_norm_data.frame.empty()) {
cv::imshow("depth_normalized", disp_norm_data.frame); // CV_8UC1
} }
char key = static_cast<char>(cv::waitKey(1)); char key = static_cast<char>(cv::waitKey(1));

View File

@ -61,6 +61,28 @@ std::shared_ptr<Extrinsics> getDefaultExtrinsics() {
return res; return res;
} }
// sgbm_matcher = cv::StereoSGBM::create(0, 16, 3);
// sgbm_matcher->setPreFilterCap(63);
// sgbm_matcher->setBlockSize(sgbmWinSize);
// sgbm_matcher->setP1(8 * sgbmWinSize * sgbmWinSize);
// sgbm_matcher->setP2(32 * sgbmWinSize * sgbmWinSize);
// sgbm_matcher->setMinDisparity(0);
// sgbm_matcher->setNumDisparities(numberOfDisparities);
// sgbm_matcher->setUniquenessRatio(10);
// sgbm_matcher->setSpeckleWindowSize(100);
// sgbm_matcher->setSpeckleRange(32);
// sgbm_matcher->setDisp12MaxDiff(1);
// bm_matcher = cv::StereoBM::create(0, 3);
// bm_matcher->setPreFilterSize(9);
// bm_matcher->setPreFilterCap(31);
// bm_matcher->setBlockSize(15);
// bm_matcher->setMinDisparity(0);
// bm_matcher->setNumDisparities(64);
// bm_matcher->setUniquenessRatio(60);
// bm_matcher->setTextureThreshold(10);
// bm_matcher->setSpeckleWindowSize(100);
// bm_matcher->setSpeckleRange(4);
MYNTEYE_END_NAMESPACE MYNTEYE_END_NAMESPACE