I have a binary image that I want to project onto a vector v such that v[i] = 1 if the image has at least one pixel in row i with a value > 0, otherwise v[i] = 0. To accomplish this, I plan on using cv::reduce to get the sum of all pixels in a row, then use a ceiling function to return a maximum value of 1.
I am running into a problem with using cv::reduce to sum all rows in an image. Here is the code I am running:
// mask is a cv::Mat of `uint8_t`
std::vector<uint8_t> reduced;
cv::reduce(mask, reduced, 1, CV_REDUCE_SUM);
This crashes with an access violation exception. However, if I sum over columns instead:
// mask is a cv::Mat of `uint8_t`
std::vector<uint8_t> reduced;
cv::reduce(mask, reduced, 0, CV_REDUCE_SUM);
this works without issue. How am I misusing cv::reduce()? This is a core piece of OpenCV, so surely I am just misusing the library :)