# What the difference between function pattern and substitute defined in GAPI\_TRANSFORM

**URL:** <https://forum.opencv.org/t/what-the-difference-between-function-pattern-and-substitute-defined-in-gapi-transform/3640>\
**Category:** C++\
**Tags:** gapi\
**Created:** [June 2, 2021, 8:09am UTC](https://forum.opencv.org/t/what-the-difference-between-function-pattern-and-substitute-defined-in-gapi-transform/3640 "2021-06-02T08:09:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CrazyDiamond](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@CrazyDiamond](https://forum.opencv.org/u/CrazyDiamond)\
**Post date:** [June 2, 2021, 8:09am UTC](https://forum.opencv.org/t/what-the-difference-between-function-pattern-and-substitute-defined-in-gapi-transform/3640/1 "2021-06-02T08:09:45Z")

</div>

Recently, I meet a fail case named "PatternMatchingIntegrationE2E.ChainTransformationsApplied " while execute opencv\_test\_gapi. So I do some research on this test program, but can’t understand this gapi pipeline very well.

This test program use a Macro called GAPI\_TRANSFORM to define a image transform action, every defined transform include two member function called pattern and substitute.

Someone can tell me what these two functions do while execute gapi pipeline?  
Thankyou.

---

<div class="post-metadata">

**Author:** ![dmitryma](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/dmitryma/32/3536_2.png) [@dmitryma](https://forum.opencv.org/u/dmitryma)\
**Post date:** [October 21, 2021, 11:40am UTC](https://forum.opencv.org/t/what-the-difference-between-function-pattern-and-substitute-defined-in-gapi-transform/3640/2 "2021-10-21T11:40:46Z")

</div>

If this test fails in plain OpenCV (either “master” or some specific version) with no modifications done to OpenCV, please feel free to report it as an issue on github.

Regarding transformations, this feature allows to define some graph transformations at the user level - where you can find matches in the graph (via method `pattern`) and replace it with another subgraph (as defined in `substitute`).

Examples: [opencv/gapi\_int\_perform\_substitution\_test.cpp at master · opencv/opencv · GitHub](https://github.com/opencv/opencv/blob/master/modules/gapi/test/internal/gapi_int_perform_substitution_test.cpp)

The idea behind that feature is that _on some platforms_ you may have superfunctions which can replace parts of the graph with some single unit (e.g. a combination of resize + color space conversion operations to be replaced by a single block). In this case, rather than changing the graph structure, one can define a transformation and map a subgraph to some smaller (or other) block.

---

<div class="post-metadata">

**Author:** ![OneJUGE](https://avatars.discourse-cdn.com/v4/letter/o/e47774/32.png) [@OneJUGE](https://forum.opencv.org/u/OneJUGE)\
**Post date:** [January 8, 2024, 3:29am UTC](https://forum.opencv.org/t/what-the-difference-between-function-pattern-and-substitute-defined-in-gapi-transform/3640/3 "2024-01-08T03:29:08Z")

</div>

Have you worked it out
