diff --git a/openbr/plugins/imgproc/samplefrommask.cpp b/openbr/plugins/imgproc/samplefrommask.cpp index 5314637..80d49ce 100644 --- a/openbr/plugins/imgproc/samplefrommask.cpp +++ b/openbr/plugins/imgproc/samplefrommask.cpp @@ -17,17 +17,15 @@ class SampleFromMaskTransform : public UntrainableTransform void project(const Template &src, Template &dst) const { Mat mask = src.file.get("Mask"); - const int count = countNonZero(mask); + Mat indices; + findNonZero(mask,indices); - if (count > 0) { - dst.m() = Mat(1,count,src.m().type()); + if (indices.total() > 0) { + dst.m() = Mat(1,indices.total(),src.m().type()); Mat masked; src.m().copyTo(masked, mask); - Mat indices; - findNonZero(masked,indices); - for (size_t j=0; j(0,j) = masked.at(indices.at(j).y,indices.at(j).x); } else {