Mat element bulk modification : negative to 0, positive to 1

c++, matrix, opencv

Solution

Look at the function threshhold. Also, this tutorial explains how to get a binary image by applying a fixed-level threshold to each array element.

cv::Mat source_array, binary_output;
cv::threshold(source_array, binary_output, 0, 1, cv::THRESH_BINARY); 

Problem

I have a matrix of negative and positive integers. I want to set negative elements to 0 and positive elements to 1. I do not want to set each element individually. Is there any function/combination of functions in OpenCv that can perform this?

Original source