X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;ds=sidebyside;f=cpp%2FsampleOpenCV%2FsampleOpenCV.cpp;h=ca4c208807662142a71876470d7f7b2e6e23f5a1;hb=a1a44e4fb655e6ba7eef56e83526bd51e92f1ba4;hp=cd81a3d9ea76bd94334771f32f361d4bdfddd9c6;hpb=562296742342225eb5b0d73fdbf5925854435146;p=201903hackathon.git diff --git a/cpp/sampleOpenCV/sampleOpenCV.cpp b/cpp/sampleOpenCV/sampleOpenCV.cpp index cd81a3d..ca4c208 100644 --- a/cpp/sampleOpenCV/sampleOpenCV.cpp +++ b/cpp/sampleOpenCV/sampleOpenCV.cpp @@ -39,9 +39,9 @@ using namespace cv; class MyListener : public IDepthDataListener { - static uint32_t const num_dist_columns_=5; - uint32_t latest_distance_[num_dist_columns_]; - uint32_t latest_distance_diff_[num_dist_columns_]; + static uint32_t const num_dist_columns_=4; + double latest_min_distance_[num_dist_columns_]; + double latest_min_distance_diff_[num_dist_columns_]; const int DELAY_BLUR = 100; // const int MAX_KERNEL_LENGTH = 31; @@ -49,10 +49,11 @@ class MyListener : public IDepthDataListener bool normblurImage = true; - const uint8_t confidence_threshold_ = 5; + const uint8_t confidence_threshold_ = 0; public : + MyListener() : undistortImage (false) { @@ -116,6 +117,32 @@ public : undistort (temp, zImage8, cameraMatrix, distortionCoefficients); } + if (normblurImage) + { + auto temp = zImage8.clone(); + for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) + { + blur( temp, zImage8, Size( i, i ), Point(-1,-1) ); + } + } + + //// Debug: show column part of image + // Mat subimg = zImage8(Rect((zImage.cols/num_dist_columns_)*3,0, zImage.cols/num_dist_columns_ , zImage8.rows)); + // imshow ("column", subimg); + + //detect column distance + auto col_width = zImage.cols/num_dist_columns_; + for (uint32_t col=0; colwidth * 4, data->height * 4), CV_8UC1); resize (zImage8, scaledZImage, scaledZImage.size()); @@ -161,6 +188,12 @@ public : undistortImage = !undistortImage; } + void toggleNormBlur() + { + std::lock_guard lock (flagMutex); + normblurImage = !normblurImage; + } + private: // adjust z value to fit fixed scaling, here max dist is 2.5m @@ -287,6 +320,7 @@ int main (int argc, char *argv[]) // create two windows namedWindow ("Depth", WINDOW_AUTOSIZE); namedWindow ("Gray", WINDOW_AUTOSIZE); + // namedWindow ("column", WINDOW_AUTOSIZE); // start capture mode if (cameraDevice->startCapture() != CameraStatus::SUCCESS) @@ -307,6 +341,12 @@ int main (int argc, char *argv[]) // toggle the undistortion of the image listener.toggleUndistort(); } + + if (currentKey == 'b') + { + // toggle the undistortion of the image + listener.toggleNormBlur(); + } } // stop capture mode