From 238781342826aa9decae3b5501e440c6fa08f06a Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Sun, 7 Feb 2021 05:42:55 +0300 Subject: [PATCH] Update imageSegmentation.cpp, imageSegmentation.py --- .../ImgTrans/imageSegmentation.cpp | 19 +++++++------------ .../imageSegmentation.py | 3 ++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp b/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp index 201466e99b..818fcb4735 100644 --- a/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp @@ -24,23 +24,16 @@ int main(int argc, char *argv[]) return -1; } - // Show source image + // Show the source image imshow("Source Image", src); //! [load_image] //! [black_bg] // Change the background from white to black, since that will help later to extract // better results during the use of Distance Transform - for ( int i = 0; i < src.rows; i++ ) { - for ( int j = 0; j < src.cols; j++ ) { - if ( src.at(i, j) == Vec3b(255,255,255) ) - { - src.at(i, j)[0] = 0; - src.at(i, j)[1] = 0; - src.at(i, j)[2] = 0; - } - } - } + Mat mask; + inRange(src, Scalar(255, 255, 255), Scalar(255, 255, 255), mask); + src.setTo(Scalar(0, 0, 0), mask); // Show output image imshow("Black Background Image", src); @@ -124,7 +117,9 @@ int main(int argc, char *argv[]) // Draw the background marker circle(markers, Point(5,5), 3, Scalar(255), -1); - imshow("Markers", markers*10000); + Mat markers8u; + markers.convertTo(markers8u, CV_8U, 10); + imshow("Markers", markers8u); //! [seeds] //! [watershed] diff --git a/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py b/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py index 0ab56cfb30..e5ed43f115 100644 --- a/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py +++ b/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py @@ -102,7 +102,8 @@ for i in range(len(contours)): # Draw the background marker cv.circle(markers, (5,5), 3, (255,255,255), -1) -cv.imshow('Markers', markers*10000) +markers_8u = (markers * 10).astype('uint8') +cv.imshow('Markers', markers_8u) ## [seeds] ## [watershed]