By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,600 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,600 IT Pros & Developers. It's quick & easy.

Loop problem in capturing image using webcam

P: 7
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:
NullReferenceException 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(image2);
.
.
.

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

//apply filter for extraction
Class2ndStage.Scan2ndStage filter7 = new Class2ndStage.Scan2ndStage(horImage, out scanning2);
objectCount2.Text = scanning2;

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

Iím using C# express edition. Could anybody help me please..
Jan 6 '07 #1
Share this Question
Share on Google+
3 Replies


jaketrimble
P: 14
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:
NullReferenceException 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(image2);
.
.
.

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

//apply filter for extraction
Class2ndStage.Scan2ndStage filter7 = new Class2ndStage.Scan2ndStage(horImage, out scanning2);
objectCount2.Text = 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
Jan 6 '07 #2

P: 7
nor
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_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if (e.Button == toolBarBtnGrab)

do
{
Thread.Sleep(500);
a++;
this.CaptureImage();
textBox1.Text = a.ToString();
Application.DoEvents();
}
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@yahoo.com) if you need to see more than this. Thanks in advance.
Jan 6 '07 #3

P: 7
nor
Hi Jake,

I've send the code to you. I hope you receive it. Pls ask if you have problem to open it.
Jan 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.