Loop problem in capturing image using webcam

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nor
    New Member
    • Aug 2006
    • 7

    Loop problem in capturing image using webcam

    Hi,

    I've application to capture video of image and grab the still image. It runs well until I put loop to regrab the still images many times automatically. It gives one exception error:
    NullReferenceEx ception was unhandled  ”Object reference not set to an instance of an object".
    I found that, this error come out because of calling file from outside of the main code of the programming.
    These are the code that calling file from the outside of the main body of code programming.

    -------------------------------------------------------------------------------------------------------------------

    //// apply filter subtract===>>>> call file from out bin folder <<<<=====
    System.Drawing. Bitmap subtract = filter1.Apply(i mage2);
    .
    .
    .

    // =====>>> call file ScanFirstStage <<<========
    //// create filter for extraction
    string scanning = "";
    ////apply filter for extraction
    ClassFirstStage .ScanFirstStage filter3 = new ClassFirstStage .ScanFirstStage (binary, out scanning);
    objectCount1.Te xt = scanning;
    .
    .
    .
    // ========>>> call file Scan2ndStage <<<=========
    // create filter for extraction
    string scanning2 = "";

    //apply filter for extraction
    Class2ndStage.S can2ndStage filter7 = new Class2ndStage.S can2ndStage(hor Image, out scanning2);
    objectCount2.Te xt = scanning2;

    -------------------------------------------------------------------------------------------------------------------

    I’m using C# express edition. Could anybody help me please..
  • jaketrimble
    New Member
    • Jan 2007
    • 14

    #2
    Originally posted by nor
    Hi,

    I've application to capture video of image and grab the still image. It runs well until I put loop to regrab the still images many times automatically. It gives one exception error:
    NullReferenceEx ception was unhandled  ”Object reference not set to an instance of an object".
    I found that, this error come out because of calling file from outside of the main code of the programming.
    These are the code that calling file from the outside of the main body of code programming.

    -------------------------------------------------------------------------------------------------------------------

    //// apply filter subtract===>>>> call file from out bin folder <<<<=====
    System.Drawing. Bitmap subtract = filter1.Apply(i mage2);
    .
    .
    .

    // =====>>> call file ScanFirstStage <<<========
    //// create filter for extraction
    string scanning = "";
    ////apply filter for extraction
    ClassFirstStage .ScanFirstStage filter3 = new ClassFirstStage .ScanFirstStage (binary, out scanning);
    objectCount1.Te xt = scanning;
    .
    .
    .
    // ========>>> call file Scan2ndStage <<<=========
    // create filter for extraction
    string scanning2 = "";

    //apply filter for extraction
    Class2ndStage.S can2ndStage filter7 = new Class2ndStage.S can2ndStage(hor Image, out scanning2);
    objectCount2.Te xt = scanning2;

    -------------------------------------------------------------------------------------------------------------------

    I’m using C# express edition. Could anybody help me please..

    not sure the problem is "calling file from outside of the main code of the programming." I am not familiar with the above scan stuff but nevertheless, the error you are receiving is usually generated when you are calling a variable that does not exsist...for instance the title of this is "LOOP PROBLEM" and I don't see any looping code...I would imagine that your loop statement has a problem like this example...

    for each i as object in myArray
    return myArray(2)
    next i

    the problem with the above example, is that "myArray(2) " may not exsist. The proper way to return this variable is...

    for each i as object in myArray
    return myArray(i)
    next i

    I am not saying yours looks anything like my examples, but look for a place in your code where you are defining a variable that should not be defined "statically ".

    Hope this helps. If not let me know or submit more of your code for review.

    peace

    Comment

    • nor
      New Member
      • Aug 2006
      • 7

      #3
      Originally posted by jaketrimble
      not sure the problem is "calling file from outside of the main code of the programming." I am not familiar with the above scan stuff but nevertheless, the error you are receiving is usually generated when you are calling a variable that does not exsist...for instance the title of this is "LOOP PROBLEM" and I don't see any looping code...I would imagine that your loop statement has a problem like this example...

      for each i as object in myArray
      return myArray(2)
      next i

      the problem with the above example, is that "myArray(2) " may not exsist. The proper way to return this variable is...

      for each i as object in myArray
      return myArray(i)
      next i

      I am not saying yours looks anything like my examples, but look for a place in your code where you are defining a variable that should not be defined "statically ".

      Hope this helps. If not let me know or submit more of your code for review.



      peace

      Hi,

      Thanks for your reply. Sorry for the vague question. Actually the reason why I call it loop problem is because, the application of program can runs well before I put loop in the code programming. Only after I put loop code, than this problem happend.

      this the code of the loop

      [
      private void toolBar_ButtonC lick(object sender, System.Windows. Forms.ToolBarBu ttonClickEventA rgs e)
      {
      if (e.Button == toolBarBtnGrab)

      do
      {
      Thread.Sleep(50 0);
      a++;
      this.CaptureIma ge();
      textBox1.Text = a.ToString();
      Application.DoE vents();
      }
      while (a %10 != 0);
      }
      ]

      And, after some experiment, I found that, the error will not come out if there are no call any file from outside of the main code of programming.
      And the code of calling the file from outside of main programming is like I've show previously.
      I hope you still can solve this problem. Plz email me (syuhadanor@yah oo.com) if you need to see more than this. Thanks in advance.

      Comment

      • nor
        New Member
        • Aug 2006
        • 7

        #4
        Hi Jake,

        I've send the code to you. I hope you receive it. Pls ask if you have problem to open it.

        Comment

        Working...