Majid
Majid

Reputation: 638

make a rectangle zero in opencv::Mat without loop

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

Answers (2)

Haris
Haris

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

guneykayim
guneykayim

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

Related Questions