openlang

Fastest approach for filling a Mat region with zero using OpenCV C++?

What would be the most efficient approach for filling one area within a grayscale Mat image with zeros (or, indeed, with another constant value)?

Is making an image of zeros and calling copyTo() the right approach, or does something better exist?

The conversation continues 3

Follow the reasoning
  1. Permalink

    Suppose a white canvas gets a rectangle painted black on it:

    cv::Mat canvas(120,120,CV_8U,cv::Scalar(255));
    canvas(cv::Rect(18,18,24,48)) = 0;
    cv::imshow("Img",canvas);
    cv::waitKey();
  2. Permalink

    Give this snippet a try

    Mat frame;
    frame = imread("images/sample-gray.jpg");
    int left=120;int top=120; int width=120;int height=120;
    Rect region = Rect(left,top,width,height);
    frame(region).setTo(cv::Scalar(0,0,0));
    imshow("display",frame);

Other sides of the same question

  1. Making the sender appear as a label instead of an email address using Java Mail

    Im sending messages through the Java Mail API. On arrival, the inbox displays the address that sent the message. Id like some…

    Replies 2Latest activity java
  2. Dynamics CRM access from TypeScript

    Because my CRM code runs in a webresource, I have to write to retrieve the entity's data. Regrettably, that expression fails…

    Replies 2Latest activity typescript
  3. What date formatting does a Gleam HTTP response header need?

    I want to send a Date header. The required format looks like this: This is my current attempt:

    Replies 3Latest activity gleam