Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8760357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:01:16+00:00 2026-06-13T15:01:16+00:00

Is there any solution in opencv 2.4 which returns non-const reference to a sub-Mat?

  • 0

Is there any solution in opencv 2.4 which returns non-const reference to a sub-Mat?
I am asking this because I want to overwrite in place a subimage, defined by a roi,
but mat(roi) returns a const reference, so I can’t write say mat(roi)=mat2,
or cv::rectangle(mat(roi), rect_relative_to_roi).

EDIT: (I’ll be more specific using Andrej’s answer)

If I have defined complex drawing functions which work on a subimage,
is the only way I can avoid sending relative coordinates to the drawing function,
that I copy back and forth the subimage I want to work with?

I mean like this:

/* Mat canvas; */
Mat subimg = canvas(roi);
draw_sth(subimg);
subimg.copyTo(canvas(roi));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:01:17+00:00Added an answer on June 13, 2026 at 3:01 pm

    Well, it turns out

    Mat subcanvas = canvas(roi);
    draw_sth(subcanvas);
    

    is the answer, it will modify the original canvas, as Mat’s are to be looked at as reference-counted smart pointers, they just point at the image data.

    On the other hand, copyTo() is not good. Take a look at the opencv code:

    //! copies the matrix content to "m".
    // It calls m.create(this->size(), this->type()).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any solution to solve the problem with this cast example? I need
Is there any solution for this problem? When using rounded-corner in IE9 with background
There is any solution to add namespaces without prefix(i mean these ns0, ns1) which
Why table params aren't allowed in SQL Server? Is there any solution to this?
I want to populate jQuery calendar with user timezone. Is there any solution in
Is there any solution to detecting if a POST have been sent with jQuery?
Is there any solution to overcome case-sensitive problem for contains method. I have code
is there any solution to show user all countries and after select country it
My question is very simple: Is there any solution to install xCode, or equivalent,
Is there any existing solution to embed the app.config file into the resulting assembly?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.