diff --git a/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_gapi.png b/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_gapi.png index 6f3147f549..f378ea870e 100644 Binary files a/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_gapi.png and b/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_gapi.png differ diff --git a/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_gapi_fluid.png b/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_gapi_fluid.png index 2a643d5a70..11bb83bf4c 100644 Binary files a/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_gapi_fluid.png and b/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_gapi_fluid.png differ diff --git a/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_ocv.png b/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_ocv.png index af2751f0c2..60b5492da8 100644 Binary files a/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_ocv.png and b/doc/tutorials/gapi/anisotropic_segmentation/pics/massif_export_ocv.png differ diff --git a/doc/tutorials/gapi/anisotropic_segmentation/pics/result.jpg b/doc/tutorials/gapi/anisotropic_segmentation/pics/result.jpg index 8c030eb020..e69cd690aa 100644 Binary files a/doc/tutorials/gapi/anisotropic_segmentation/pics/result.jpg and b/doc/tutorials/gapi/anisotropic_segmentation/pics/result.jpg differ diff --git a/doc/tutorials/gapi/anisotropic_segmentation/pics/segm.gif b/doc/tutorials/gapi/anisotropic_segmentation/pics/segm.gif index dbf7ec3342..a984d9da36 100644 Binary files a/doc/tutorials/gapi/anisotropic_segmentation/pics/segm.gif and b/doc/tutorials/gapi/anisotropic_segmentation/pics/segm.gif differ diff --git a/doc/tutorials/gapi/anisotropic_segmentation/pics/segm_fluid.gif b/doc/tutorials/gapi/anisotropic_segmentation/pics/segm_fluid.gif index 3a887e86df..2180b434d4 100644 Binary files a/doc/tutorials/gapi/anisotropic_segmentation/pics/segm_fluid.gif and b/doc/tutorials/gapi/anisotropic_segmentation/pics/segm_fluid.gif differ diff --git a/doc/tutorials/gapi/anisotropic_segmentation/porting_anisotropic_segmentation.markdown b/doc/tutorials/gapi/anisotropic_segmentation/porting_anisotropic_segmentation.markdown index 6b3c29e7c4..cf0190373f 100644 --- a/doc/tutorials/gapi/anisotropic_segmentation/porting_anisotropic_segmentation.markdown +++ b/doc/tutorials/gapi/anisotropic_segmentation/porting_anisotropic_segmentation.markdown @@ -106,9 +106,7 @@ like this: Note that this code slightly changes from the original one: forming up the resulting image is also a part of the pipeline (done with -cv::gapi::addWeighted). Normalization of orientation and coherency -images is still done by traditional OpenCV (using cv::normalize) as -G-API doesn't provide such kernel at the moment. +cv::gapi::addWeighted). Result of this G-API pipeline bit-exact matches the original one (given the same input image): @@ -211,7 +209,7 @@ algorithm versions: ==6117== Once done, we can inspect the collected profiles with -[Massif Visualizer](@https://github.com/KDE/massif-visualizer) +[Massif Visualizer](https://github.com/KDE/massif-visualizer) (installed in the above step). Below is the visualized memory profile of the original OpenCV version @@ -231,7 +229,7 @@ Now let's have a look on the profile of G-API version: Once G-API computation is created and its execution starts, G-API allocates all required memory at once and then the memory profile remains flat until the termination of the program. Massif reports us -peak memory consumption of 10.6 MiB. +peak memory consumption of 11.4 MiB. A reader may ask a right question at this point -- is G-API that bad? What is the reason in using it than? @@ -367,9 +365,9 @@ Fluid backend. Now it looks like this: ![Memory profile: G-API/Fluid port of Anisotropic Image Segmentation sample](pics/massif_export_gapi_fluid.png) -Now the tool reports 3.8MiB -- and we just changed a few lines in our -code, without modifying the graph itself! It is a ~2.8X improvement of -the previous G-API result, and 2X improvement of the original OpenCV +Now the tool reports 4.7MiB -- and we just changed a few lines in our +code, without modifying the graph itself! It is a ~2.4X improvement of +the previous G-API result, and ~1.6X improvement of the original OpenCV version. Let's also examine how the internal representation of the graph now diff --git a/samples/cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi.cpp b/samples/cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi.cpp index 447e395d2b..a6b82e5839 100644 --- a/samples/cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi.cpp +++ b/samples/cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi.cpp @@ -45,8 +45,12 @@ int main() cv::GMat imgBin = imgCoherencyBin & imgOrientationBin; cv::GMat out = cv::gapi::addWeighted(in, 0.5, imgBin, 0.5, 0.0); + // Normalize extra outputs + cv::GMat imgCoherencyNorm = cv::gapi::normalize(imgCoherency, 0, 255, cv::NORM_MINMAX); + cv::GMat imgOrientationNorm = cv::gapi::normalize(imgOrientation, 0, 255, cv::NORM_MINMAX); + // Capture the graph into object segm - cv::GComputation segm(cv::GIn(in), cv::GOut(out, imgCoherency, imgOrientation)); + cv::GComputation segm(cv::GIn(in), cv::GOut(out, imgCoherencyNorm, imgOrientationNorm)); // Define cv::Mats for output data cv::Mat imgOut, imgOutCoherency, imgOutOrientation; @@ -54,10 +58,6 @@ int main() // Run the graph segm.apply(cv::gin(imgIn), cv::gout(imgOut, imgOutCoherency, imgOutOrientation)); - // Normalize extra outputs (out of the graph) - cv::normalize(imgOutCoherency, imgOutCoherency, 0, 255, cv::NORM_MINMAX); - cv::normalize(imgOutOrientation, imgOutOrientation, 0, 255, cv::NORM_MINMAX); - cv::imwrite("result.jpg", imgOut); cv::imwrite("Coherency.jpg", imgOutCoherency); cv::imwrite("Orientation.jpg", imgOutOrientation); diff --git a/samples/cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi_fluid.cpp b/samples/cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi_fluid.cpp index bdec8f0fdb..71271c37f7 100644 --- a/samples/cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi_fluid.cpp +++ b/samples/cpp/tutorial_code/gapi/porting_anisotropic_image_segmentation/porting_anisotropic_image_segmentation_gapi_fluid.cpp @@ -50,8 +50,12 @@ int main() auto imgBin = imgCoherencyBin & imgOrientationBin; cv::GMat out = cv::gapi::addWeighted(in, 0.5, imgBin, 0.5, 0.0); + // Normalize extra outputs + cv::GMat imgCoherencyNorm = cv::gapi::normalize(imgCoherency, 0, 255, cv::NORM_MINMAX); + cv::GMat imgOrientationNorm = cv::gapi::normalize(imgOrientation, 0, 255, cv::NORM_MINMAX); + // Capture the graph into object segm - cv::GComputation segm(cv::GIn(in), cv::GOut(out, imgCoherency, imgOrientation)); + cv::GComputation segm(cv::GIn(in), cv::GOut(out, imgCoherencyNorm, imgOrientationNorm)); // Define cv::Mats for output data cv::Mat imgOut, imgOutCoherency, imgOutOrientation; @@ -75,10 +79,6 @@ int main() //! [kernel_pkg_use] //! [kernel_pkg_proper] - // Normalize extra outputs (out of the graph) - cv::normalize(imgOutCoherency, imgOutCoherency, 0, 255, cv::NORM_MINMAX); - cv::normalize(imgOutOrientation, imgOutOrientation, 0, 255, cv::NORM_MINMAX); - cv::imwrite("result.jpg", imgOut); cv::imwrite("Coherency.jpg", imgOutCoherency); cv::imwrite("Orientation.jpg", imgOutOrientation);