Skip to content

Commit 9405c6d

Browse files
Improvement of array of equivalences’ upper bound + fix some wrong comments
1 parent 0d7666a commit 9405c6d

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

modules/imgproc/src/connectedcomponents.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ namespace cv{
288288
int r = range.start;
289289
chunksSizeAndLabels_[r] = range.end;
290290

291-
LabelT label = LabelT((r * imgLabels_.cols + 1) / 2 + 1);
291+
LabelT label = LabelT((r + 1) / 2) * LabelT((imgLabels_.cols + 1) / 2) + 1;
292292

293293
const LabelT firstLabel = label;
294294
const int w = img_.cols;
@@ -615,6 +615,10 @@ namespace cv{
615615

616616
//merge labels of different chunks
617617
mergeLabels8Connectivity(imgLabels, P, chunksSizeAndLabels);
618+
619+
for (int i = 0; i < h; i = chunksSizeAndLabels[i]){
620+
flattenL(P, int((i + 1) / 2) * int((w + 1) / 2) + 1, chunksSizeAndLabels[i + 1], nLabels);
621+
}
618622
}
619623
else{
620624
//First scan, each thread works with chunk of img.rows/nThreads rows
@@ -623,10 +627,10 @@ namespace cv{
623627

624628
//merge labels of different chunks
625629
mergeLabels4Connectivity(imgLabels, P, chunksSizeAndLabels);
626-
}
627-
628-
for (int i = 0; i < h; i = chunksSizeAndLabels[i]){
629-
flattenL(P, (i * w + 1) / 2 + 1, chunksSizeAndLabels[i + 1], nLabels);
630+
631+
for (int i = 0; i < h; i = chunksSizeAndLabels[i]){
632+
flattenL(P, int(i * w + 1) / 2 + 1, chunksSizeAndLabels[i + 1], nLabels);
633+
}
630634
}
631635

632636
//Array for statistics dataof threads
@@ -842,7 +846,7 @@ namespace cv{
842846

843847
chunksSizeAndLabels_[r] = range.end + (range.end % 2);
844848

845-
LabelT label = LabelT((r + 1) * (imgLabels_.cols + 1) / 4);
849+
LabelT label = LabelT((r + 1) / 2) * LabelT((imgLabels_.cols + 1) / 2) + 1;
846850

847851
const LabelT firstLabel = label;
848852
const int h = img_.rows, w = img_.cols;
@@ -2540,7 +2544,7 @@ namespace cv{
25402544
//0 0 0 0 0...
25412545
//1 0 1 0 1...
25422546
//............
2543-
const size_t Plength = ((size_t(h) + 1) * (size_t(w) + 1)) / 4 + 1;
2547+
const size_t Plength = size_t(((h + 1) / 2) * size_t((w + 1) / 2)) + 1;
25442548

25452549
//Array used to store info and labeled pixel by each thread.
25462550
//Different threads affect different memory location of chunksSizeAndLabels
@@ -2562,7 +2566,7 @@ namespace cv{
25622566

25632567
LabelT nLabels = 1;
25642568
for (int i = 0; i < h; i = chunksSizeAndLabels[i]){
2565-
flattenL(P, (i + 1) * (w + 1) / 4, chunksSizeAndLabels[i + 1], nLabels);
2569+
flattenL(P, LabelT((i + 1) / 2) * LabelT((w + 1) / 2) + 1, chunksSizeAndLabels[i + 1], nLabels);
25662570
}
25672571

25682572
//Array for statistics data
@@ -2602,7 +2606,7 @@ namespace cv{
26022606
//0 0 0 0 0...
26032607
//1 0 1 0 1...
26042608
//............
2605-
const size_t Plength = ((size_t(h) + 1) * (size_t(w) + 1)) / 4 + 1;
2609+
const size_t Plength = size_t(((h + 1) / 2) * size_t((w + 1) / 2)) + 1;
26062610

26072611
LabelT *P = (LabelT *)fastMalloc(sizeof(LabelT) *Plength);
26082612
P[0] = 0;

modules/video/include/opencv2/video/background_segm.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor
188188
189189
A shadow is detected if pixel is a darker version of the background. The shadow threshold (Tau in
190190
the paper) is a threshold defining how much darker the shadow can be. Tau= 0.5 means that if a pixel
191-
is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiarra,
191+
is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiara,
192192
*Detecting Moving Shadows...*, IEEE PAMI,2003.
193193
*/
194194
CV_WRAP virtual double getShadowThreshold() const = 0;
@@ -289,7 +289,7 @@ class CV_EXPORTS_W BackgroundSubtractorKNN : public BackgroundSubtractor
289289
290290
A shadow is detected if pixel is a darker version of the background. The shadow threshold (Tau in
291291
the paper) is a threshold defining how much darker the shadow can be. Tau= 0.5 means that if a pixel
292-
is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiarra,
292+
is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiara,
293293
*Detecting Moving Shadows...*, IEEE PAMI,2003.
294294
*/
295295
CV_WRAP virtual double getShadowThreshold() const = 0;

modules/video/src/bgfg_KNN.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class BackgroundSubtractorKNNImpl : public BackgroundSubtractorKNN
235235
// Tau - shadow threshold. The shadow is detected if the pixel is darker
236236
//version of the background. Tau is a threshold on how much darker the shadow can be.
237237
//Tau= 0.5 means that if pixel is more than 2 times darker then it is not shadow
238-
//See: Prati,Mikic,Trivedi,Cucchiarra,"Detecting Moving Shadows...",IEEE PAMI,2003.
238+
//See: Prati,Mikic,Trivedi,Cucchiara,"Detecting Moving Shadows...",IEEE PAMI,2003.
239239

240240
//model data
241241
int nLongCounter;//circular counter

modules/video/src/bgfg_gaussmix2.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class BackgroundSubtractorMOG2Impl : public BackgroundSubtractorMOG2
386386
// Tau - shadow threshold. The shadow is detected if the pixel is darker
387387
//version of the background. Tau is a threshold on how much darker the shadow can be.
388388
//Tau= 0.5 means that if pixel is more than 2 times darker then it is not shadow
389-
//See: Prati,Mikic,Trivedi,Cucchiarra,"Detecting Moving Shadows...",IEEE PAMI,2003.
389+
//See: Prati,Mikic,Trivedi,Cucchiara,"Detecting Moving Shadows...",IEEE PAMI,2003.
390390

391391
String name_;
392392

@@ -461,7 +461,7 @@ struct GaussBGStatModel2Params
461461
// Tau - shadow threshold. The shadow is detected if the pixel is darker
462462
//version of the background. Tau is a threshold on how much darker the shadow can be.
463463
//Tau= 0.5 means that if pixel is more than 2 times darker then it is not shadow
464-
//See: Prati,Mikic,Trivedi,Cucchiarra,"Detecting Moving Shadows...",IEEE PAMI,2003.
464+
//See: Prati,Mikic,Trivedi,Cucchiara,"Detecting Moving Shadows...",IEEE PAMI,2003.
465465
};
466466

467467
struct GMM
@@ -472,7 +472,7 @@ struct GMM
472472

473473
// shadow detection performed per pixel
474474
// should work for rgb data, could be usefull for gray scale and depth data as well
475-
// See: Prati,Mikic,Trivedi,Cucchiarra,"Detecting Moving Shadows...",IEEE PAMI,2003.
475+
// See: Prati,Mikic,Trivedi,Cucchiara,"Detecting Moving Shadows...",IEEE PAMI,2003.
476476
CV_INLINE bool
477477
detectShadowGMM(const float* data, int nchannels, int nmodes,
478478
const GMM* gmm, const float* mean,

0 commit comments

Comments
 (0)