forked from opencv/opencv_contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnectedcomponents.cpp
49 lines (33 loc) · 1.72 KB
/
connectedcomponents.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 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.
#include "precomp.hpp"
using namespace cv;
using namespace cv::cuda;
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
void cv::cuda::connectedComponents(InputArray, OutputArray, int, int, ConnectedComponentsAlgorithmsTypes) { throw_no_cuda(); }
void cv::cuda::connectedComponents(InputArray, OutputArray, int, int) { throw_no_cuda(); }
#else /* !defined (HAVE_CUDA) */
namespace cv { namespace cuda { namespace device { namespace imgproc {
void BlockBasedKomuraEquivalence(const cv::cuda::GpuMat& img, cv::cuda::GpuMat& labels);
}}}}
void cv::cuda::connectedComponents(InputArray img_, OutputArray labels_, int connectivity,
int ltype, ConnectedComponentsAlgorithmsTypes ccltype) {
const cv::cuda::GpuMat img = img_.getGpuMat();
cv::cuda::GpuMat& labels = labels_.getGpuMatRef();
CV_Assert(img.channels() == 1);
CV_Assert(connectivity == 8);
CV_Assert(ltype == CV_32S);
CV_Assert(ccltype == CCL_BKE || ccltype == CCL_DEFAULT);
int iDepth = img_.depth();
CV_Assert(iDepth == CV_8U || iDepth == CV_8S);
labels.create(img.size(), CV_MAT_DEPTH(ltype));
if ((ccltype == CCL_BKE || ccltype == CCL_DEFAULT) && connectivity == 8 && ltype == CV_32S) {
using cv::cuda::device::imgproc::BlockBasedKomuraEquivalence;
BlockBasedKomuraEquivalence(img, labels);
}
}
void cv::cuda::connectedComponents(InputArray img_, OutputArray labels_, int connectivity, int ltype) {
cv::cuda::connectedComponents(img_, labels_, connectivity, ltype, CCL_DEFAULT);
}
#endif /* !defined (HAVE_CUDA) */