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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:27:29+00:00 2026-06-02T14:27:29+00:00

The code compiles successfully but I am getting the following error when I try

  • 0

The code compiles successfully but I am getting the following error when I try to execute the code with some images.

malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) – 1) * 2])) – __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) – 1)) & ~((2 * (sizeof(size_t))) – 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)’ failed.
Aborted

My code is:

#include "opencv2/modules/imgproc/include/opencv2/imgproc/imgproc.hpp"
#include "opencv2/modules/highgui/include/opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>

using namespace cv;

/// Global variables
int const min_BINARY_value = 0;
int const max_BINARY_value = 255;

Mat src, src_gray, new_image;
const char* window_name = "Web Safe Colors";

/**
 * @function main
 */
int main( int argc, char** argv )
{
  double sum=0, mean=0;

  /// Load an image
  src = imread( argv[1], 1 );

  /// Convert the image to Gray
  cvtColor( src, src_gray, CV_RGB2GRAY );

  /// Create new image matrix
  new_image = Mat::ones( src_gray.size(), src_gray.type() );

  /// Calculate sum of pixels
  for( int y = 0; y < src_gray.rows; y++ )
  { 
    for( int x = 0; x < src_gray.cols; x++ )
    { 
      sum = sum + src_gray.at<Vec3b>(y,x)[0];
    }
  }

  /// Calculate mean of pixels
  mean = sum / (src_gray.rows * src_gray.cols);

  /// Perform conversion to binary
  for( int y = 0; y < src_gray.rows; y++ )
  { 
    for( int x = 0; x < src_gray.cols; x++ )
    { 
      if(src_gray.at<Vec3b>(y,x)[0] <= mean)
        new_image.at<Vec3b>(y,x)[0] = min_BINARY_value;
      else
        new_image.at<Vec3b>(y,x)[0] = max_BINARY_value;
    }
  }

  /// Create a window to display results
  namedWindow( window_name, CV_WINDOW_AUTOSIZE );

  imshow( window_name, new_image );
  /// Wait until user finishes program
  while(true)
    {
      int c;
      c = waitKey( 20 );
      if( (char)c == 27 )
    { break; }
    }

}

Can you please help me identify the problem?

  • 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-02T14:27:32+00:00Added an answer on June 2, 2026 at 2:27 pm

    I cannot reproduce the exact error message you get. On my computer your program stopped with a segmentation fault.

    The reason for this was, that you are accessing the pixels of your gray value images as if they were rgb images. So instead of

    new_image.at<Vec3b>(y,x)[0]
    

    you need to use

    new_image.at<uchar>(y,x)
    

    Because in a gray scale image every pixel only has a single value instead of a vector of 3 values (red, green and blue). After I applied this changes your program ran without errors and produced the expected output of an thresholded binary image.

    It is possible that because of this you are overwriting some other memory opencv currently used and that this memory corruption then lead to your error message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code compiles, and runs successfully locally, but not on another server. Both machines
The following code compiles in Visual C++ and gcc, but fails with Code Warrior
the following code compiles with Visual Studio 2008 but not with g++ on Mac
My cocos2d iOS game code compiles and runs without error in Xcode 4.2.1 but
The following code compiles, but fails with a NullReferenceException : class Test { public
The following code compiles successfully and returns the correct results when called the first
The code compiles without too much complaint, but the last step fails with the
This code compiles fine with GCC and Clang but not with MSVC 2010: #include
The following source code compiles correctly with Visual Studio 2010: namespace NS { class
Getting following build error: error X2230: the type 'ASA.Log.ServiceLogger.IASALog' is in assembly 'ASA.Log.ServiceLogger' that

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.