Get size of cv::GMat

Hi~ I am a startter of g-API. This question might be very simple to you.

for a cv::Mat A, we can easily get the size of A by A.size(), A.cols, A.rows. Is there a similar API for a cv::GMat object?

for example, I can resize B with the size of A

cv::Mat A = cv::imread(...);
cv::Mat B = cv::imread(...);
cv::resize(B, B, A.size());

How can get the size of A if I want to use g-API?

Thx in advance!

1 Like

Hi @carter54

No, there’s no way to do that. At the point when you define a Graph (and so, operate with GMat and other objects), there’s no any image information associated with it.

The image information appears when the graph is compiled - via compile(), compileStreaming() or implicitly via .apply() - and the image information is passed in.

The idea behind this is that graph is optimized to manage a certain image resolution. Sometimes it can be changed with .reshape(), but note it only applies to a compiled graph object (where GMat & etc are already optimized out - as those objects are only used to construct the graph).

There are places, still, where you can access information about the GMat dimensions during the graph compile process (this is the stage where this information is known). The Operation’s outMeta() callback is one of those, if you’re writing your own Operations.

2 Likes