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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:59:42+00:00 2026-05-26T17:59:42+00:00

I have some allocated cv::Mat face; with actual data in it and I want

  • 0

I have some allocated cv::Mat face; with actual data in it and I want to perform something along the lines of the following:

cv::Mat gray_image;
cv::Mat x_gradient_image;
cv::Mat temp;

cv::cvtColor(face, gray_image, CV_RGB2GRAY);
cv::Sobel(gray_image, temp, 1, 1, 0); 
cv::convertScaleAbs(temp, x_gradient_image, 1, 0);

This causes the program to crash, but I assumed in the new C++ API that cv::Mat objects were good at allocating their own memory. What is the simplest way to allocate the memory for those cv::Mat objects?

  • 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-26T17:59:42+00:00Added an answer on May 26, 2026 at 5:59 pm

    I changed the depth parameter in the call to Sobel and your code worked for me:

    #include <iostream>
    #include "opencv2/core/core.hpp"
    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/imgproc/imgproc.hpp"
    
    int main(int argc, const char * argv[]) {
    
        cv::Mat face;
        // read an image
        if (argc < 2)
            face = cv::imread("../../IMG_0080.jpg");
        else
            face = cv::imread(argv[1]);
    
        if (!face.data) {
            std::cout << "Image file not found\n";
            return 1;
        }
    
        cv::Mat gray_image;
        cv::Mat x_gradient_image;
        cv::Mat temp;
    
        cv::cvtColor(face, gray_image, CV_RGB2GRAY);
        cv::Sobel(gray_image, temp, 5, 1, 0); 
        cv::convertScaleAbs(temp, x_gradient_image, 1, 0);
    
        // show the image in a window
        cv::imshow("so8044872", x_gradient_image);
        // wait for key
        cv::waitKey(0);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some arbitrary pixel data that I want to save as a PNG.
Say I have some data allocated somewhere in my program, like: some_type a; and
I have a fortran pointer, referring to some allocated memory. I want to hash
I have some data loaded as a np.ndarray and need to convert it to
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some memory that has been allocated on device that is just a
If I have allocated some amount of memory via ::operator new(nbytes) and later I
Lets say I have allocated some memory in my background thread, that is, a
i have some memory issues in program and i have the following questions. question
I have some data type which, if I were to use plain old C

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.