TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bahar Jalali
NA
185
305.4k
a small problem, Object reference not set to an instance of an object
Jun 4 2012 12:16 PM
hi
i want to run this source code but i can't;
here is code URL:
http://www.oliveragustin.com/background-subtraction-in-c-part-2/
a
nd it's the source code :
var image = new Image<Bgr, byte>(filename);
// threshold values for each channel
var thresholds = new[] { new TRange<int>(70, 255), new TRange<int>(0, 255), new TRange<int>(0, 255) };
Image<Gray, byte>[] grays = image.Convert<Lab, byte>().Split();
// threshold each channel
for (int i = 0; i < 3; i++)
{
grays[i]._ThresholdToZero(new Gray(thresholds[i].LowerValue));
grays[i]._ThresholdToZeroInv(new Gray(thresholds[i].UpperValue));
grays[i]._ThresholdBinary(new Gray(1), new Gray(255));
}
// merge the thresholded array of binary images above
var mask = grays[0].And(grays[1].And(grays[2]));
// result
var resultImage = image.Copy(mask);
my problem is this line :
var thresholds = new [] {new TRange<int>(70,255), new TRange<int>(0,255), new TRange<int>(0,255)};
i don't know how must i define above line in c#! what is TRange? i defined it like the following code but it has error
"Object reference not set to an instance of an object";
public struct TRange<T>
{
public int LowerValue, UpperValue;
public TRange(int x, int y)
{
LowerValue = x;
UpperValue = y;
}
}
// background subtraction in NewBGSubtraction
private void NewBGSubtraction(Bitmap filename, bool displayResult)
{
var image = new Image<Bgr, byte>(filename);
// threshold values for each channel
var thresholds = new[] {new TRange<int>(70, 255), new TRange<int>(0, 255), new TRange<int>(0, 255) };
Image<Gray, byte>[] grays = image.Convert<Lab, byte>().Split();
// threshold each channel
for (int i = 0; i < 3; i++)
{
grays[i]._ThresholdToZero(new Gray(thresholds[i].LowerValue));
grays[i]._ThresholdToZeroInv(new Gray(thresholds[i].UpperValue));
grays[i]._ThresholdBinary(new Gray(1), new Gray(255));
}
// merge the thresholded array of binary images above
var mask = grays[0].And(grays[1].And(grays[2]));
// result
var resultImage = image.Copy(mask);
pictureBox2.Image = resultImage.Bitmap;
}
Reply
Answers (
4
)
c# running exe through batch gives file not found.
StartIndex cannot be less than zero.