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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:24:20+00:00 2026-06-07T05:24:20+00:00

I am trying to programm an edge detection method. And I have used emgucv

  • 0

I am trying to programm an edge detection method. And I have used emgucv Image class. Since I need gray values I have declared it as

Image<Gray,float> MyImage = new Image<Gray,float>;

I select an image and assign its pixel values into MyImage as

public void selectImage()
          { 
               OpenFileDialog opp = new OpenFileDialog();
              if (opp.ShowDialog() == DialogResult.OK)
              {                 
                   MyImage = new Image<Gray,float>(opp.FileName);
                  InputArray = new Image<Gray, float>(opp.FileName);
                  Convert.ToString(MyImage);
                  pictureBox1.Image = MyImage.ToBitmap();                
              }             
          }

When I click on edge detection button it calls the main recursive function

private void detect_edges_Click(object sender, EventArgs e)
        {          
           hueckel_operator(1, 1);
        }

This operator repeats itself with 5pixel intervals. In other words I apply it on x axis by incrementing x parameter by 5 and at the end of the row I increment y axis by 5 and so on.

In hueckel_operator, the function “a()” which calculates again a very heavy formula is being called 8 times. Here is the a() function

 public double a(int j,  int counter6,  int counter7)
            {

                for (int II = 0; II <= j ; II++)
                {
                    for (KK = 1; KK < 70; KK++)
                    {
                         x_value = input_i_x(KK); //this function brings the x coordinate
                         y_value = input_i_y(KK); // this function brings the y coordinate

                result += HueckelDisk(x_value,y_value,j) * MyImage[x_value+counter6, y_value+counter7].Intensity;
                //MyImage.Dispose();
                    }
                }                           
                return result;
            }

But the problem is approximately at the coordinate (75,5) it throws a stack overflow exception. I debugged it with performance analyse and MyImage seems to eat all memory. You probably wants to see recursive function but since it is too big I can not put it here and I am sure that recursive function (hueckel_operator()) can not reach terminating condition since I found out how many times it has been called. What I want is to find out if there is another way to calculate “result” in a more efficient way.

My other question is that, object MyImage is used in function a() 69*j times and does it mean that it allocates memory space 69*j times whenever a() is called?

During my desperate tries, I have declared and defined almost every variable as global in order to reduce the memory usage because I have thought otherwise whenever hueckel_operator() and a() are called, local variables would allocate extra memory in stack over and over, is it a good or necessary approach?

I use 4 very nested and heavy functions and I don’t use any class. Would it be the main problem? To be honest I don’t see anything here to convert into class.

I know, I have asked too many questions but I am really desperate right now. I am reading articles since some weeks and I guess I need a kick start. Any help would be appreciated.

enter image description here

  • 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-07T05:24:21+00:00Added an answer on June 7, 2026 at 5:24 am

    A stack overflow exception doesn’t really have much to do with memory usage – it’s from stack usage. In your case, a recursive call.

    Recursion can only go so deep until the stack is exhausted. Once that happens, you get your stack overflow.

    If you are not in an unbounded recursion but you need to go deeper, you can specify the stack size when you create a thread, and run your recursive function on that:

    var stackSize = 10000000;
    var thread = new Thread(new ThreadStart(StartDetection), stackSize);
    

    However, the default size is 1MB – which is quite a bit for most tasks. You may want to verify your recursion is in fact not unbound, or that you can’t reduce or remove it.

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

Sidebar

Related Questions

I'm trying to rewrite method paintEvent in my programm and change it. void MainWindow::paintEvent(QPaintEvent
I'm trying to write a program in C++ language. Class Edge indicates the connection
I am trying to solve a problem. This program contains all the edge in
I am trying to start a X-Programm (e.g. gedit or Firefox) with crontab. I
I'm trying to program my first GUI-class in Java, using the Window Builder. Ok,
I'm trying to program a graph class using an adjacent list from an example
I have been trying some programs in the C Language and come across to
currently i am trying to laod *.obj-files into my programm. My code is based
I'm trying to to convert from a decimal number into a binary number. Have
I trying to write a programm for file compare. For example: file1 1 2

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.