Commit 4c0cb257 authored by Jason Newton's avatar Jason Newton

connectedComponents: peep-hole optimizations, mostly surrouding the fact that…

connectedComponents: peep-hole optimizations, mostly surrouding the fact that cv::Mat::at is expensive in a tight-loop -also added a "blobstats" version
parent 45b4f4f3
......@@ -1091,9 +1091,24 @@ enum { TM_SQDIFF=0, TM_SQDIFF_NORMED=1, TM_CCORR=2, TM_CCORR_NORMED=3, TM_CCOEFF
CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ,
OutputArray result, int method );
struct CV_EXPORTS ConnectedComponentStats
{
int32_t lower_x;
int32_t lower_y;
int32_t upper_x;
int32_t upper_y;
double centroid_x;
double centroid_y;
uint64_t integral_x;
uint64_t integral_y;
uint32_t area;
};
//! computes the connected components labeled image of boolean image I with 4 or 8 way connectivity - returns N, the total
//number of labels [0, N-1] where 0 represents the background label.
//number of labels [0, N-1] where 0 represents the background label. L's value type determines the label type, an important
//consideration based on the total number of labels or alternatively the total number of pixels.
CV_EXPORTS_W uint64_t connectedComponents(Mat &L, const Mat &I, int connectivity = 8);
CV_EXPORTS_W uint64_t connectedComponents(Mat &L, const Mat &I, std::vector<ConnectedComponentStats> &statsv, int connectivity = 8);
//! mode of the contour retrieval algorithm
......
This diff is collapsed.
......@@ -12,7 +12,7 @@ static void on_trackbar(int, void*)
{
Mat bw = threshval < 128 ? (img < threshval) : (img > threshval);
Mat labelImage(img.size(), CV_32S);
int nLabels = connectedComponents(labelImage, bw, 8);
uint64_t nLabels = connectedComponents(labelImage, bw, 8);
Vec3b colors[nLabels];
colors[0] = Vec3b(0, 0, 0);//background
for(int label = 1; label < nLabels; ++label){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment