I have a matrix of negative and positive integers. I want to set the negative elements to 0 and the positive elements to 1. I do not want to set each element separately.
Is there any function / combination of functions in OpenCv that can accomplish this?
Take a look at the threshhold function . In addition, this tutorial explains how to get a binary image by applying a fixed-level threshold to each element of the array.
cv::Mat source_array, binary_output; cv::threshold(source_array, binary_output, 0, 1, cv::THRESH_BINARY);
, , . , . .
cv::threshold(m, m, 0, 1, cv::THRESH_BINARY);
cvThreshold(m, m, 0, 1, THRESH_BINARY);
m = m > 0
cv.Threshold(m, m, 0, 1, cv.CV_THRESH_BINARY)