Updates gapi tutorial using normalize kernel
Changes doc, images and sample code itself
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 83 KiB |
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 85 KiB |
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 75 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 140 KiB After Width: | Height: | Size: 183 KiB |
Before Width: | Height: | Size: 173 KiB After Width: | Height: | Size: 220 KiB |
@ -106,9 +106,7 @@ like this:
|
|||||||
|
|
||||||
Note that this code slightly changes from the original one: forming up
|
Note that this code slightly changes from the original one: forming up
|
||||||
the resulting image is also a part of the pipeline (done with
|
the resulting image is also a part of the pipeline (done with
|
||||||
cv::gapi::addWeighted). Normalization of orientation and coherency
|
cv::gapi::addWeighted).
|
||||||
images is still done by traditional OpenCV (using cv::normalize) as
|
|
||||||
G-API doesn't provide such kernel at the moment.
|
|
||||||
|
|
||||||
Result of this G-API pipeline bit-exact matches the original one
|
Result of this G-API pipeline bit-exact matches the original one
|
||||||
(given the same input image):
|
(given the same input image):
|
||||||
@ -211,7 +209,7 @@ algorithm versions:
|
|||||||
==6117==
|
==6117==
|
||||||
|
|
||||||
Once done, we can inspect the collected profiles with
|
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).
|
(installed in the above step).
|
||||||
|
|
||||||
Below is the visualized memory profile of the original OpenCV version
|
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
|
Once G-API computation is created and its execution starts, G-API
|
||||||
allocates all required memory at once and then the memory profile
|
allocates all required memory at once and then the memory profile
|
||||||
remains flat until the termination of the program. Massif reports us
|
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?
|
A reader may ask a right question at this point -- is G-API that bad?
|
||||||
What is the reason in using it than?
|
What is the reason in using it than?
|
||||||
@ -367,9 +365,9 @@ Fluid backend. Now it looks like this:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Now the tool reports 3.8MiB -- and we just changed a few lines in our
|
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.8X improvement of
|
code, without modifying the graph itself! It is a ~2.4X improvement of
|
||||||
the previous G-API result, and 2X improvement of the original OpenCV
|
the previous G-API result, and ~1.6X improvement of the original OpenCV
|
||||||
version.
|
version.
|
||||||
|
|
||||||
Let's also examine how the internal representation of the graph now
|
Let's also examine how the internal representation of the graph now
|
||||||
|
@ -45,8 +45,12 @@ int main()
|
|||||||
cv::GMat imgBin = imgCoherencyBin & imgOrientationBin;
|
cv::GMat imgBin = imgCoherencyBin & imgOrientationBin;
|
||||||
cv::GMat out = cv::gapi::addWeighted(in, 0.5, imgBin, 0.5, 0.0);
|
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
|
// 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
|
// Define cv::Mats for output data
|
||||||
cv::Mat imgOut, imgOutCoherency, imgOutOrientation;
|
cv::Mat imgOut, imgOutCoherency, imgOutOrientation;
|
||||||
@ -54,10 +58,6 @@ int main()
|
|||||||
// Run the graph
|
// Run the graph
|
||||||
segm.apply(cv::gin(imgIn), cv::gout(imgOut, imgOutCoherency, imgOutOrientation));
|
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("result.jpg", imgOut);
|
||||||
cv::imwrite("Coherency.jpg", imgOutCoherency);
|
cv::imwrite("Coherency.jpg", imgOutCoherency);
|
||||||
cv::imwrite("Orientation.jpg", imgOutOrientation);
|
cv::imwrite("Orientation.jpg", imgOutOrientation);
|
||||||
|
@ -50,8 +50,12 @@ int main()
|
|||||||
auto imgBin = imgCoherencyBin & imgOrientationBin;
|
auto imgBin = imgCoherencyBin & imgOrientationBin;
|
||||||
cv::GMat out = cv::gapi::addWeighted(in, 0.5, imgBin, 0.5, 0.0);
|
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
|
// 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
|
// Define cv::Mats for output data
|
||||||
cv::Mat imgOut, imgOutCoherency, imgOutOrientation;
|
cv::Mat imgOut, imgOutCoherency, imgOutOrientation;
|
||||||
@ -75,10 +79,6 @@ int main()
|
|||||||
//! [kernel_pkg_use]
|
//! [kernel_pkg_use]
|
||||||
//! [kernel_pkg_proper]
|
//! [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("result.jpg", imgOut);
|
||||||
cv::imwrite("Coherency.jpg", imgOutCoherency);
|
cv::imwrite("Coherency.jpg", imgOutCoherency);
|
||||||
cv::imwrite("Orientation.jpg", imgOutOrientation);
|
cv::imwrite("Orientation.jpg", imgOutOrientation);
|
||||||
|