Revision history [back]

Problem with cv::reduce when trying to sum both columns and rows

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;


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;


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 :)

Problem with cv::reduce when trying to sum both columns and rows

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;

// mask is a cv::Mat of uint8_t

this works without issue. How am I misusing cv::reduce()cv::reduce? This is a core piece of OpenCV, so surely I am just misusing the library :)