G-API Stereo operation and tests#19732
Conversation
1878cdc to
d19f4c4
Compare
|
@AsyaPronina @TolyaTalamanov Please review |
| namespace stereo { | ||
| namespace cpu { | ||
|
|
||
| GAPI_EXPORTS_W GKernelPackage kernels(); |
There was a problem hiding this comment.
I believe it shouldn't be in python now, GAPI_EXPORTS would be enough
| namespace stereo { | ||
|
|
||
| enum OutputFormat { | ||
| disparity, |
There was a problem hiding this comment.
Capital letters are usually used + enum class
There was a problem hiding this comment.
Capital letters are usually used for enum values and mixed-case style for enum name, @TolyaTalamanov , do you agree?
There was a problem hiding this comment.
OUTPUT_FORMAT -> OutputFormat
disparity -> DISPARITY
| depth | ||
| }; | ||
|
|
||
| G_TYPED_KERNEL(GStereoBM, <GMat(GMat, GMat,const int , const int, const OutputFormat, const int, const double, const double)>, "org.opencv.stereoBM") { |
There was a problem hiding this comment.
GMat, const int , -> GMat, const int, const ...
There was a problem hiding this comment.
Didn`t get
Could you explain?
There was a problem hiding this comment.
Have a look on alignment
| }; | ||
|
|
||
| G_TYPED_KERNEL(GStereoBM, <GMat(GMat, GMat,const int , const int, const OutputFormat, const int, const double, const double)>, "org.opencv.stereoBM") { | ||
| static GMatDesc outMeta(GMatDesc ly, GMatDesc ry, const int, const int, const OutputFormat, const int ddtype, |
There was a problem hiding this comment.
Just wondering what is the ddtype ?
There was a problem hiding this comment.
Its a type of output cv::Mat
ddtype -> outputType
There was a problem hiding this comment.
I meant it just dtype
There was a problem hiding this comment.
outputType -> dtype
| cv::Mat disp; | ||
| cv::StereoBM::create(numDisparities, blockSize) -> compute(left, right, disp); | ||
|
|
||
| // See https://answers.opencv.org/question/199915/how-to-get-depth-from-disparity-map/?sort=votes#:~:text=Z%20%3D%20B*f%20%2F%20disparity%20is%20the%20correct%20formula%20to,get%20the%20depth%20in%20mm. |
There was a problem hiding this comment.
I believe such kind of reference shouldn't be there
| GAPI_Assert(ry.chan == 1); | ||
| GAPI_Assert(ry.depth == CV_8U); | ||
|
|
||
| return ddtype == CV_16U ? ly.withDepth(CV_16U) : ly.withDepth(CV_16F); |
There was a problem hiding this comment.
dpype -> outputType
|
|
||
| cv::gapi::GKernelPackage cv::gapi::stereo::cpu::kernels() | ||
| { | ||
| static auto pkg = cv::gapi::kernels |
There was a problem hiding this comment.
static auto pkg = cv::gapi::kernels<GCPUStereoBM>();
| #include <opencv2/gapi/cpu/stereo.hpp> | ||
| #include <opencv2/gapi/cpu/gcpukernel.hpp> | ||
|
|
||
| #include <iostream> |
|
|
||
| namespace | ||
| { | ||
| #define STR_CPU [] () { return cv::compile_args(cv::gapi::use_only{cv::gapi::str::cpu::kernels()}); } |
There was a problem hiding this comment.
How is it called in another tests ?
There was a problem hiding this comment.
I did a parameterized tests
Now it is used there
7622eea to
fadfe89
Compare
|
|
||
| namespace cv { | ||
| namespace gapi { | ||
| namespace ster { |
There was a problem hiding this comment.
Why ster?
Where did the stereo go?
There was a problem hiding this comment.
In this case there is name collision of namespace stereo and operation stereo
There was a problem hiding this comment.
Please discuss namespace name with the team -- to comply with OpenCV modules names we should create calib3d namespace, but we are focusing on addition of stereoscopic functionality, so may be namespace should be named as stereo or stereoscopic.
There was a problem hiding this comment.
cv::gapi::ster -> cv::gapi::calib3d
| namespace cv { | ||
|
|
||
| namespace gapi { | ||
| namespace ster { |
| namespace stereo { | ||
|
|
||
| enum OutputFormat { | ||
| disparity, |
There was a problem hiding this comment.
Capital letters are usually used for enum values and mixed-case style for enum name, @TolyaTalamanov , do you agree?
|
|
||
| G_TYPED_KERNEL(GStereo, <GMat(GMat, GMat, const cv::gapi::ster::OUTPUT_FORMAT, const int)>, "org.opencv.stereo") { | ||
| static GMatDesc outMeta(GMatDesc ly, GMatDesc ry, | ||
| const cv::gapi::ster::OUTPUT_FORMAT, |
There was a problem hiding this comment.
Should we also check that OUTPUT_FORMAT is one of existent?
| ) | ||
| { | ||
| cv::Mat disp; | ||
| cv::StereoBM::create( |
There was a problem hiding this comment.
You shouldn't create new instance each time for cv::StereoBM if you have opportunity to use state...
9ed4aa5 to
a1a2e73
Compare
|
|
||
| #include <opencv2/calib3d.hpp> | ||
|
|
||
| GAPI_OCV_KERNEL_ST(GCPUStereo, cv::gapi::ster::GStereo, cv::gapi::ster::StereoSetup) |
There was a problem hiding this comment.
StereoSetup may be just a structure to initialize state and state may be just StereoBM class, don't you think?
There was a problem hiding this comment.
We also have to keep focus and baseLine to calculate depths from disparity
Easier way to keep it all in StereoSetup structure, I think...
Or what do you mean?
There was a problem hiding this comment.
Please split the StereoSetup structure from cv::StereoBM. Lets cv::StereoBM be implementation details and be hidden from user. Lets cv::StereoBM be the state and StereoSetup be the initialization structure.
There was a problem hiding this comment.
If you can't retrieve focus and baseline from the cv::StereoBM, then create a structure to hold cv::StereoBM and focus + baseline. Lets this structure be the state and StereoSetup be the structure to just initialize the state.
|
|
||
| enum class OutputFormat { | ||
| DISPARITY, | ||
| DEPTHS |
|
|
||
| namespace calib3d { | ||
|
|
||
| struct StereoSetup { |
There was a problem hiding this comment.
Please move this out of calib3d namespace.
There was a problem hiding this comment.
Please also see how the initialization parameters are declared and documented here: https://github.com/opencv/opencv/blob/master/modules/gapi/include/opencv2/gapi/video.hpp#L22
Suggest to declare and document them the same way.
|
|
||
| #include <opencv2/calib3d.hpp> | ||
|
|
||
| GAPI_OCV_KERNEL_ST(GCPUStereo, cv::gapi::calib3d::GStereo, cv::gapi::calib3d::StereoSetup) |
There was a problem hiding this comment.
Please see my answers in discussion about cv::gapi::calib3d::StereoSetup as a state.
There was a problem hiding this comment.
Can you please explain why it is stateful?
There was a problem hiding this comment.
Its stateful for not to create cv::gapi::calib3d::StereoSetup every time kernel is called
There was a problem hiding this comment.
Also its needed for keep approved kernel API and also have opportunity to configure blockSize, numDisparity and etc.
|
|
||
| @param ly Y plane from left camera: 8-bit unsigned 1-channel matrix of @ref CV_8UC1 type | ||
| @param ry Y plane from right camera: 8-bit unsigned 1-channel matrix of @ref CV_8UC1 type | ||
| @param oF the enum class specifies do disparity to depth conversion or not |
There was a problem hiding this comment.
enum class to specify to make disparity to depth conversion or not
|
|
||
| } // namespace calib3d | ||
|
|
||
| /** @brief Extracts disparity or, optionally, depth information from stereo-pair. |
There was a problem hiding this comment.
Optionally is extra here.
We provide return type exclusively: user can retrieve either disparity or depth
There was a problem hiding this comment.
Extract disparity/depth information depending on passed StereoOutputFormat argument
There was a problem hiding this comment.
Please fix detailed description the same way
|
|
||
| template<> struct CompileArgTag<cv::gapi::StereoInitParam> { | ||
| static const char* tag() { | ||
| return "org.opencv.stereoSetup"; |
dmatveev
left a comment
There was a problem hiding this comment.
Good overall! Some clarification is required though.
| /** @brief Structure for the Stereo operation setup parameters.*/ | ||
| struct GAPI_EXPORTS StereoSetup { | ||
| double baseline; | ||
| double focus; | ||
| cv::Ptr<cv::StereoBM> stereoBM; | ||
| }; |
There was a problem hiding this comment.
That is state in stateful kernel
There was a problem hiding this comment.
It should be hidden if it is not yet
| @param ly Y plane from left camera: 8-bit unsigned 1-channel matrix of @ref CV_8UC1 type | ||
| @param ry Y plane from right camera: 8-bit unsigned 1-channel matrix of @ref CV_8UC1 type | ||
| @param oF the enum class to specify to make disparity to depth conversion or not | ||
| @param dtype is a type of output @ref cv::Mat. Can be @ref CV_16U or @ref CV_16F |
There was a problem hiding this comment.
Does this apply to both output types? (Disparity vs. depth)
|
|
||
| #include <opencv2/calib3d.hpp> | ||
|
|
||
| GAPI_OCV_KERNEL_ST(GCPUStereo, cv::gapi::calib3d::GStereo, cv::gapi::calib3d::StereoSetup) |
There was a problem hiding this comment.
Can you please explain why it is stateful?
| disp = (stereoSetup.focus * stereoSetup.baseline) / disp; | ||
| } | ||
|
|
||
| disp.convertTo(out_disp, dtype); |
There was a problem hiding this comment.
so is disp ok with such dtype? does it conform to the ocv behavior?
e0cf9ca to
d8ef570
Compare
370e9ea to
53d6089
Compare
214eb27 to
fee2816
Compare
4b2b505 to
e6f52b0
Compare
| DEPTH_FLOAT16, | ||
| DEPTH_FLOAT32, | ||
| DISPARITY_FIXED16_11_5, | ||
| DISPARITY_FIXED16_12_4 |
There was a problem hiding this comment.
This is questionable, at least I'd give some better names to this enum in the future iteration (after merge).
FLOAT16 -> F16, FLOAT32 -> F32, FIXED16_ -> Q (as for quantized).
There was a problem hiding this comment.
When you'll do this, please don't break the existing enumerations, simply provides aliases with the same name (cc: @AsyaPronina @rgarnov )
|
Fantastic! Thanks a lot @aDanPin, @AsyaPronina, @rgarnov for your work! And kudos to @alalek for merging this! |
| DISPARITY_FIXED16_12_4 | ||
| }; | ||
|
|
||
| namespace calib3d { |
There was a problem hiding this comment.
calib3d
In OpenCV 5.0 calib3d is gone (see the "next" branch and PR #18940).
Used functionality is moved to "stereo" namespace.
Perhaps it makes sense to use new names for namespaces and functions instead.
There was a problem hiding this comment.
Thanks Alexander,
This namespace here is used only to hold an Operation's type -- the user code is supposed to use cv::gapi::stereo instead so we can move these types around easily with no visible impact
-D
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.