Reputation: 638
what's the efficient way to make a special block of opencv::Mat zero? (without loop)
Mat freq;
// Set some frequencies to 0
for (int y=0; y<freq.rows; y++)
{
for (int x=Start; x<freq.cols; x++)
{
if (x>Start || y>Start)
freq.at<double>(y,x) = 0.0;
}
}
// Set some frequencies to 0
for (int y=Start; y<freq.rows; y++)
{
for (int x=0; x<freq.cols; x++)
{
freq.at<double>(y,x) = 0.0;
}
}
Upvotes: 0
Views: 3087
Reputation: 14053
Just try below code
Mat src;
Mat roi = src(Rect(x,y,width,height)); // Set Roi
roi.setTo(0); // Set all pixel to 0 on both src and roi
Upvotes: 2
Reputation: 5250
You can create a zero matrix. Here is the link. You can make your entire matrix zero or create a smaller zero matrix and assign it to desired part of the original matrix.
Upvotes: 0