Commit 0f880500cd0ff0b6dcec0b68213f87e9d84c1aab

Authored by Scott Klum
1 parent 18590845

Fixed logic error in samplefrommask

openbr/plugins/imgproc/samplefrommask.cpp
@@ -17,17 +17,15 @@ class SampleFromMaskTransform : public UntrainableTransform @@ -17,17 +17,15 @@ class SampleFromMaskTransform : public UntrainableTransform
17 void project(const Template &src, Template &dst) const 17 void project(const Template &src, Template &dst) const
18 { 18 {
19 Mat mask = src.file.get<Mat>("Mask"); 19 Mat mask = src.file.get<Mat>("Mask");
20 - const int count = countNonZero(mask); 20 + Mat indices;
  21 + findNonZero(mask,indices);
21 22
22 - if (count > 0) {  
23 - dst.m() = Mat(1,count,src.m().type()); 23 + if (indices.total() > 0) {
  24 + dst.m() = Mat(1,indices.total(),src.m().type());
24 25
25 Mat masked; 26 Mat masked;
26 src.m().copyTo(masked, mask); 27 src.m().copyTo(masked, mask);
27 28
28 - Mat indices;  
29 - findNonZero(masked,indices);  
30 -  
31 for (size_t j=0; j<indices.total(); j++) 29 for (size_t j=0; j<indices.total(); j++)
32 dst.m().at<uchar>(0,j) = masked.at<uchar>(indices.at<Point>(j).y,indices.at<Point>(j).x); 30 dst.m().at<uchar>(0,j) = masked.at<uchar>(indices.at<Point>(j).y,indices.at<Point>(j).x);
33 } else { 31 } else {