Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Connected Components Labeling in CUDA #3153

Merged
merged 1 commit into from
Feb 4, 2022
Merged

Add Connected Components Labeling in CUDA #3153

merged 1 commit into from
Feb 4, 2022

Conversation

stal12
Copy link
Contributor

@stal12 stal12 commented Jan 20, 2022

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Pull Request Description

This pull request adds Connected Components Labeling in CUDA.
The implemented algorithm is Block-Based Komura Equivalence.

force_builders=linux,docs,Custom
buildworker:Custom=linux-4,linux-6
build_image:Custom=ubuntu-cuda:18.04

opencv_extra=4.x

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution!

// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use short license header: https://github.com/opencv/opencv/wiki/Coding_Style_Guide#file-structure

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

opencv_contrib_source_code/modules/cudaimgproc/samples/connected_components.cpp

*/
CV_EXPORTS_AS(ConnectedComponentsWithAlgorithm) void connectedComponents(InputArray image, OutputArray labels,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please start from lower case:

connectedComponentsWithAlgorithm

Ref: https://github.com/opencv/opencv/wiki/Coding_Style_Guide#naming-conventions


*/
CV_EXPORTS_AS(ConnectedComponentsWithAlgorithm) void connectedComponents(InputArray image, OutputArray labels,
int connectivity, int ltype, int ccltype);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to use enum's name instead of int in parameters.

Comment on lines 56 to 62
namespace cv { namespace cuda { namespace device
{
namespace imgproc
{

constexpr int kblock_rows = 16;
constexpr int kblock_cols = 16;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid indentation in namespaces

case CV_16U: normalize_labels_impl<ushort>(labels); break;
case CV_16S: normalize_labels_impl<short>(labels); break;
case CV_32S: normalize_labels_impl<int>(labels); break;
default: break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break;

CV_Assert(0) ?

// Note that this is the maximum number of labels for 4-way connectivity
{
input <<
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid using of MatCommaInitializer. It generates very huge binary code.

Use ctors with C++11 std::initializer_list instead.

Ref: https://github.com/opencv/opencv/blob/4.5.5/modules/core/include/opencv2/core/mat.hpp#L2247

@stal12
Copy link
Contributor Author

stal12 commented Feb 3, 2022

Updated with the suggested improvements

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for update!

LGTM 👍

@opencv-pushbot opencv-pushbot merged commit 933b011 into opencv:4.x Feb 4, 2022
@alalek alalek mentioned this pull request Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants