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 6219823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:51:03+00:00 2026-05-24T07:51:03+00:00

in my programm I have function that takes the image from camera and should

  • 0

in my programm I have function that takes the image from camera and should pack all data in OpenCV Mat structure. From the camera I get width, height and unsigned char* to the image buffer. My Question is how I can create Mat from this data, if I have global Mat variable. The type for Mat structure I took CV_8UC1.

Mat image_;

function takePhoto() {
    unsigned int width = getWidthOfPhoto();
    unsinged int height = getHeightOfPhoto();
    unsinged char* dataBuffer = getBufferOfPhoto();
    Mat image(Size(width, height), CV_8UC1, dataBuffer, Mat::AUTO_STEP);

    printf("width: %u\n", image.size().width);
    printf("height: %u\n", image.size().height);

    image_.create(Size(image.size().width, image.size().height), CV_8UC1);
    image_ = image.clone();

    printf("width: %u\n", image_.size().width);
    printf("height: %u\n", image_.size().height);
}

When I test my program, I get right width and height of image, but width and height of my global Mat image_ is 0. How I can put the data in my global Mat varible correctly?

Thank you.

  • 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-05-24T07:51:04+00:00Added an answer on May 24, 2026 at 7:51 am

    Unfortunately, neither clone() nor copyTo() successfully copy the values of width/height to another Mat. At least on OpenCV 2.3! It’s a shame, really.

    However, you could solve this issue and simplify your code by making the function return the Mat. This way you won’t need to have a global variable:

    Mat takePhoto() 
    {
        unsigned int width = getWidthOfPhoto();
        unsigned int height = getHeightOfPhoto();
        unsigned char* dataBuffer = getBufferOfPhoto();
        Mat image(Size(width, height), CV_8UC1, dataBuffer, Mat::AUTO_STEP);
        return Mat;
    }
    
    int main()
    {
        Mat any_img = takePhoto();
        printf("width: %u\n", any_img.size().width);
        printf("height: %u\n", any_img.size().height);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that takes 2 variables, one for the database connection and
I am developing a C# program, and i have one function that consumes too
I have a program that uses the mt19937 random number generator from boost::random. I
I have a class which has a constructor that takes a const char* .
Okay here's the program I have typed up(stdio.h is included also): /* function main
in a C program I have an long* that I want to serialize (thus
I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I am working on a project that requires some image processing. The front end
So I have an excel workbook that has a nice global map of shaperange

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.