Hi Guys,
I hope you can help me because I've tried everything and don't know what else to do. I keep getting the error "Object reference not set to an instance of an object" and I can't seem to figure out what the problem is. I've even tried instantiating the object and nothing seems to be working. Can anyone help me? The code is below. Thanks.

public virtual void Track(Bitmap bitmap, out Window targetRoi, out Window searchRoi, out Dictionary<string, string> information)
        {
            int MEANSHIFT_ITERATIONS = 30;
            const int DISTANCE_ITERATIONS = 30;

            float bhatCoeff1 = 0;
            float bhatCoeff2 = 0;
            int dIterations = 0;
            int msIterations = 0;
            float distance = 0;
            Bitmap cropped = null;

            int centreX = _targetRoi.CentreX; //ERROR
            int centreY = _targetRoi.CentreY;

                        
            //Limit the iterations to a fixed number to avoid performance degradation
            do
            {
                _searchRoi.EnsureLimits();
                //Find candidate model at the region of interest
                _histCand = _imgProc.Create1DHistogram(bitmap, _histTarget.BinCount1, _histTarget.BinCount2, _histTarget.BinCount3, _targetRoi.RegionOfInterest, _searchRoi.RegionOfInterest);

                //Get BC
                bhatCoeff1 = Metric.Evaluate(new BhattacharryyaCoefficient(_histTarget, _histCand));

                //Calculate moments                
                cropped = GetImageSection(bitmap, _targetRoi);//crop the region of interest                
                _moment = new MSMoment(cropped, _histTarget, _histCand);
                                
                //Find the new centre
                centreX = _targetRoi.RegionOfInterest.X + (int)(_moment.FirstMomentX / _moment.ZerothMoment);
                centreY = _targetRoi.RegionOfInterest.Y + (int)(_moment.FirstMomentY / _moment.ZerothMoment);
                
                //Move the roi & search window to the new centroid
                _targetRoi.Offset(centreX - _targetRoi.CentreX, centreY - _targetRoi.CentreY);
                _searchRoi.Offset(centreX - _searchRoi.CentreX, centreY - _searchRoi.CentreY);
                
                //Find candidate model at the new location
                _searchRoi.EnsureLimits();
                _histCand = _imgProc.Create1DHistogram(bitmap, _histTarget.BinCount1, _histTarget.BinCount2, _histTarget.BinCount3, _targetRoi.RegionOfInterest, _searchRoi.RegionOfInterest);

                //Get BC at the new location
                bhatCoeff2 = Metric.Evaluate(new BhattacharryyaCoefficient(_histTarget, _histCand));

                while ((bhatCoeff2 < bhatCoeff1) && (dIterations < DISTANCE_ITERATIONS))
                {
                    centreX = (int)Math.Ceiling(((float)(centreX + _previousCentreX)) / 2);
                    centreY = (int)Math.Ceiling(((float)(centreY + _previousCentreY)) / 2);

                    //Move ROI to the new location
                    _targetRoi.Offset(centreX - _targetRoi.CentreX, centreY - _targetRoi.CentreY);
                    _searchRoi.Offset(centreX - _searchRoi.CentreX, centreY - _searchRoi.CentreY);
                                        
                    //Find candidate model at the new location
                    _searchRoi.EnsureLimits();
                    _histCand = _imgProc.Create1DHistogram(bitmap, _histTarget.BinCount1, _histTarget.BinCount2, _histTarget.BinCount3, _targetRoi.RegionOfInterest, _searchRoi.RegionOfInterest);

                    //Get BC at the new location
                    bhatCoeff2 = Metric.Evaluate(new BhattacharryyaCoefficient(_histTarget, _histCand));

                    dIterations++;
                }

                //Calculate the distance between two vectors
                distance = (float)Math.Sqrt(Math.Pow((centreX - _previousCentreX), 2)
                    + Math.Pow((centreY - _previousCentreY), 2));

                _previousCentreX = centreX;
                _previousCentreY = centreY;

                msIterations++;

            } while ((distance >= 0.1) && (msIterations < MEANSHIFT_ITERATIONS));
                       
            //save info
            //_moment.Information.Clear();
            _moment.Information.Add("Meanshift Iterations: ", msIterations.ToString());
            _moment.Information.Add("Bhattacharyya Coeff: ", bhatCoeff2.ToString());

            //check validity
            if (centreX > 0 && centreY > 0)
            {
                //Move the roi & search window to the new centroid
                _targetRoi.Offset(centreX - _targetRoi.CentreX, centreY - _targetRoi.CentreY);
                _searchRoi.Offset(centreX - _searchRoi.CentreX, centreY - _searchRoi.CentreY);

                _moment.Information.Add("Centroid: ", _targetRoi.CentreX.ToString() + ", " + _targetRoi.CentreY.ToString());

                //_processedImage = Drawer.DrawMoment(bitmap, _moment, new Point(centreX, centreY));
                _processedImage = Drawer.DrawWindow(bitmap, _targetRoi, Color.Red);
                _processedImage = Drawer.DrawWindow(bitmap, _searchRoi, Color.Yellow);
            }

            //save ROIs for next frame
            targetRoi = _targetRoi;
            searchRoi = _searchRoi;
            information = _moment.Information;
        }

Recommended Answers

All 18 Replies

Without context or definitions of some of these functions/classes, it's hard to tell what isn't being initialized. Have you tried stepping through the code to find out exactly which line the error is occuring on?

There's a few functions that I am not sure what they are doing. For example, when you are assigning cropped=GetImageSection() are you sure GetImageSection is returning a new bitmap, rather than just modifying the bitmap? Stepping through the code will help narrow down the problematic line of code, then from there it may be necessary to post the referenced method/class/function calls that are on that line.

Looks like the _targetRoi variable is not initialized. It must be initialized in the constructor of your class or in the declaration of _targetRoi.

Looks like the _targetRoi variable is not initialized. It must be initialized in the constructor of your class or in the declaration of _targetRoi.

That is sort of jumping to conclusions. It is marked as an output variable, meaning that it is expecting an already-constructed Window class as an argument. In order to know this for sure, we need to see the calling code.

If you don't have the calling code (you are writing a library for someone else to use) then it may be a good idea to do some checks on the arguments to throw more meaningful exceptions:

if (_targetoi==null)
   throw new exception ("_targetoi is non initialized");

That is sort of jumping to conclusions. It is marked as an output variable, meaning that it is expecting an already-constructed Window class as an argument. In order to know this for sure, we need to see the calling code.

If you don't have the calling code (you are writing a library for someone else to use) then it may be a good idea to do some checks on the arguments to throw more meaningful exceptions:

if (_targetoi==null)
   throw new exception ("_targetoi is non initialized");

@skatamatic
No, actually you are mixing things up. _targetRoi with "_" is not the out parameter, but targetRoi without the "_". So _targetRoi must have been initialized, too. This is what I was referring to.

@skatamatic
No, actually you are mixing things up. _targetRoi with "_" is not the out parameter, but targetRoi without the "_". So _targetRoi must have been initialized, too. This is what I was referring to.

Ah yes that's right. You need to initialize _targetRoi. Maybe use variables that differ more in name than a '_'.

Could you tell us on which line you got the error?
Obviously some object is not instantiated, but from your code it is hard to tell.

Could you tell us on which line you got the error?
Obviously some object is not instantiated, but from your code it is hard to tell.

I didn't notice either at first glance. It's on line 13, commented with //ERROR.

@skatamatic: ther goes another one of my hairs:'(

That is sort of jumping to conclusions. It is marked as an output variable, meaning that it is expecting an already-constructed Window class as an argument. In order to know this for sure, we need to see the calling code.

If you don't have the calling code (you are writing a library for someone else to use) then it may be a good idea to do some checks on the arguments to throw more meaningful exceptions:

if (_targetoi==null)
   throw new exception ("_targetoi is non initialized");

Please take a look at the highlighted lines. When I run the debugger, these two lines were highlighted.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;

using ImageProcessor;
using Tracker;
using UIGraphic;
using Statistic;

namespace CVMeanshift
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
_path = "..\\..\\";
//Load images
_isTracking = false;
}

//create the target selector
private void CreateSelector()
{
if (_selector == null)
{
_selector = new Selector(picPreview.Width, picPreview.Height);
_selector.TargetROISelected = new
Selector.TargetSelected(this.CreateTargetModel);
//wire preview window events to selector's events
picPreview.MouseDown += new MouseEventHandler(_selector.OnMouseDown);
picPreview.MouseMove += new MouseEventHandler(_selector.OnMouseMove);
picPreview.MouseUp += new MouseEventHandler(_selector.OnMouseUp);
}
}

//create the model when the target is slected
private void CreateTargetModel()
{
//create the model
Tracker.CreateTargetModel((Bitmap)picPreview.Image, Bin1, Bin2, Bin3,
_selector.TargetWindow, _selector.SearchWindow);
//show target histogram
DisplayHistogram(ref _histTarget, picPreview, picTargetHist);
}

private void DisplayHistogram(ref Histogram hist, PictureBox picBox, PictureBox
histBox)
{
Image bmp = picBox.Image;
if (bmp != null)
{
hist = CreateHistogram((Bitmap)bmp);
histBox.Refresh(); //force paint event
}
}

private int Bin1
{
get { return Convert.ToInt32(textBox1.Text); }
}

private int Bin2
{
get { return Convert.ToInt32(textBox2.Text); }
}

private int Bin3
{
get { return Convert.ToInt32(textBox3.Text); }
}

//creates the histograms
private Histogram CreateHistogram(Bitmap img)
{
return _imgProc.Create1DHistogram(img, Bin1, Bin2, Bin3);
}

//Displays the histogram
private void DisplayModel(Histogram model, int height, int width,
PaintEventArgs e, Color color, int binRange)
{
if (model != null)
{
Pen p = new Pen(color, 1);
SolidBrush b = new SolidBrush(color);
float[] copy = new float[model.Data.Length];
Array.Copy(model.Data, copy, model.Data.Length);
Array.Sort(copy);
float max = copy[copy.Length - 1];
float scale = height / max;
if (float.IsNaN(scale))
scale = 1;
//Approximation: divide by total bins and remove 4 from width to
account for picbox border
float w = (float)(width - 4) / (float)(model.Data.Length);
for (int count = 0; count < model.Data.Length; count++)
{
if (model.Data[count] > 0)
{
e.Graphics.DrawRectangle(p, (float)count * w, (float)height -
(model.Data[count] * scale), w, model.Data[count] * scale);
e.Graphics.FillRectangle(b, (float)count * w, (float)height -
(model.Data[count] * scale), w, model.Data[count] * scale);

}
}
}
}

private void DisplayInformation(Dictionary<string, string> information)
{
lblInfo.Text = "";
foreach (KeyValuePair<string, string> kv in information)
{
lblInfo.Text += kv.Key + ": " + kv.Value + Environment.NewLine;
}
lblInfo.Refresh();
}

//Track the object
private void TrackObject(Bitmap bmp)
{
//run track on the tracker to find centroid
Window roi;
Window searchRoi;
Dictionary<string, string> information;

Tracker.Track(bmp, out roi, out searchRoi, out information);

Bitmap b = Tracker.ProcessedImage;

//Draw the centroid if valid
if (roi.CentreX > 0 && roi.CentreY > 0)
{
//Display Info
DisplayInformation(information);
}

picPreview.Image = b;
picPreview.Refresh();

//Display the candidate histogram
if (_tracker.GetType().Name != "Centroid")
DisplayHistogram(ref _histCandidate, picPreview, picCandidateHist);

//Drawer.DrawWindow(picPreview, roi, Color.Red);
//Drawer.DrawWindow(picPreview, searchRoi, Color.Yellow);
}

private ITracker Tracker
{
get
{
if (_tracker == null)
CreateTracker();

return _tracker;
}
}

private void CreateTracker()
{
if (radTrackerCentroid.Checked)
_tracker = new TrackerFactory(TrackerType.CENTROID).Tracker;
else if (radTrackerMS.Checked)
_tracker = new TrackerFactory(TrackerType.MEANSHIFT).Tracker;
else if (radTrackerMSK.Checked)
_tracker = new TrackerFactory(TrackerType.MEANSHIFTKERNEL).Tracker;
else if (radTrackerMSKBG.Checked)
_tracker = new TrackerFactory(TrackerType.MEANSHIFTKERNELBG).Tracker;
}

#region "CONTROL EVENTS"
private void picTargetHist_Paint(object sender, PaintEventArgs e)
{
DisplayModel(_histTarget, picTargetHist.Height, picTargetHist.Width, e,
Color.Red, Bin1 * Bin2 * Bin3);
}

private void picCandidateHist_Paint(object sender, PaintEventArgs e)
{
DisplayModel(_histCandidate, picCandidateHist.Height,
picCandidateHist.Width, e, Color.Blue, Bin1 * Bin2 * Bin3);
}

private void timer1_Tick(object sender, EventArgs e)
{
if (_count < _trackSequenceCount)
{
//set the next image
Bitmap bmp = (Bitmap)Image.FromFile(_path + "\\" + _count +
_imageFileExtension);
TrackObject(bmp); //do tracking
_count++; //move to next image
}
else
{
btnTrack.Text = "Start Tracking";
_count = 0;
timer1.Enabled = false;
timer1.Stop();
}
}

private void btnLoadSequence_Click(object sender, EventArgs e)
{
folderBrowserDialog1.SelectedPath = "C:\\CodeProject\\AviSequence";
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{

Cursor.Current = Cursors.WaitCursor;

//_isTracking = true;
_path = folderBrowserDialog1.SelectedPath;

picPreview.Image = null;
picPreview.Refresh();
_histTarget = null;
_histCandidate = null;
picTargetHist.Refresh();
picCandidateHist.Refresh();
lblInfo.Text = "";
_count = 0;
string imagePath = "";
Bitmap b = null;

string[] files = Directory.GetFiles(_path, "*.jpg");

if (files.Length > 0)
{
imagePath = files[0];
b = (Bitmap)Image.FromFile(imagePath);
}
else
{
files = Directory.GetFiles(_path, "*.bmp");
imagePath = files[0];
b = (Bitmap)Image.FromFile(imagePath);
_imageFileExtension = ".bmp";
}
picPreview.Image = b;
FileInfo fi = new FileInfo(imagePath);
_imageFileExtension = fi.Extension;
picPreview.Refresh();

_trackSequenceCount = files.Length;

CreateSelector();

Cursor.Current = Cursors.Default;
}
}


private void btnTrack_Click(object sender, EventArgs e)
{
//start the frame grabber
if (btnTrack.Text == "Start Tracking")
{
_isTracking = true;
btnTrack.Text = "Stop Tracking";

timer1.Enabled = true;
timer1.Start();
}
else if (btnTrack.Text == "Stop Tracking")
{
timer1.Stop();
timer1.Enabled = false;
btnTrack.Text = "Start Tracking";
}
}
#endregion

string _imageFileExtension = ".jpg";
int _trackSequenceCount = 0;
int _count = 0;
string _path = "";
Processor _imgProc = new Processor();
Histogram _histTarget = null;
Histogram _histCandidate = null;
Selector _selector = null;
ITracker _tracker = null;
bool _isTracking = false;

private void picPreview_Click(object sender, EventArgs e)
{

}

}
}

Ah yes that's right. You need to initialize _targetRoi. Maybe use variables that differ more in name than a '_'.

I tried initializing _targetRoi. But when the program still didn't compile, I took it out.

Without context or definitions of some of these functions/classes, it's hard to tell what isn't being initialized. Have you tried stepping through the code to find out exactly which line the error is occuring on?

There's a few functions that I am not sure what they are doing. For example, when you are assigning cropped=GetImageSection() are you sure GetImageSection is returning a new bitmap, rather than just modifying the bitmap? Stepping through the code will help narrow down the problematic line of code, then from there it may be necessary to post the referenced method/class/function calls that are on that line.

I stepped through the code and I have posted the code with the highlighted error lines in red. Thanks

Ah yes that's right. You need to initialize _targetRoi. Maybe use variables that differ more in name than a '_'.

You were right. I had to initialize _targetRoi. Once I put in the exception argument, it stated that VALUE CANNOT BE NULL. PARAMETER NAME: _targetRoi is non initialized. So I went ahead and did this:

Meanshift _targetRoi = new Meanshift();

Now it says Tracker.Meanshift does not contain a definition for CentreX and no extension method 'CentreX' accepting a first argument of type 'Tracker.Meanshift' could be found. (Are you missing a using directive or assembly)

This is the code the error is referring to: int centreX = _targetRoi.CentreX;

Ah yes that's right. You need to initialize _targetRoi. Maybe use variables that differ more in name than a '_'.

You were right. I had to initialize _targetRoi. Once I put in the exception argument, it stated that VALUE CANNOT BE NULL. PARAMETER NAME: _targetRoi is non initialized. So I went ahead and did this:

Meanshift _targetRoi = new Meanshift();

Now it says Tracker.Meanshift does not contain a definition for CentreX and no extension method 'CentreX' accepting a first argument of type 'Tracker.Meanshift' could be found. (Are you missing a using directive or assembly)

This is the code the error is referring to: int centreX = _targetRoi.CentreX;

... So I went ahead and did this:

Meanshift _targetRoi = new Meanshift();

Now it says Tracker.Meanshift does not contain a definition for CentreX and no extension method 'CentreX' accepting a first argument of type 'Tracker.Meanshift' could be found. (Are you missing a using directive or assembly)

This is the code the error is referring to: int centreX = _targetRoi.CentreX;

Are you sure _targetRoi is of type Meanshift? Please post the whole code, including the initialization of _targetRoi. And please format as code.

I changed it to:

Window _targetRoi = new Window(); (highlighted in RED)
Then it gave me the same error in the code highlighted in GREEN.

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

using ImageProcessor;
using UIGraphic;
using Statistic;

namespace Tracker
{
    public class Meanshift : ITracker
    {
        public Meanshift()
        {
            _imgProc = new Processor(); //create image processor
        }

        #region ITracker Members

        public virtual void CreateTargetModel(Bitmap bitmap, int binCountCh1, int  
        binCountCh2, int binCountCh3, Window targetRoi, UIGraphic.Window searchRoi)
        {
            _targetRoi = targetRoi;
            _searchRoi = searchRoi;

            //set previous centre values
            _previousCentreX = _targetRoi.CentreX;
            _previousCentreY = _targetRoi.CentreY;

            searchRoi.EnsureLimits(); //make sure it is not out of the picture
            
            //create target histogram
            _histTarget = _imgProc.Create1DHistogram(bitmap, binCountCh1, binCountCh2, 
             binCountCh3, targetRoi.RegionOfInterest, _searchRoi.RegionOfInterest);
        }

        public virtual void Track(Bitmap bitmap, out Window targetRoi, out Window 
        searchRoi, out Dictionary<string, string> information)
        {
            const int MEANSHIFT_ITERATIONS = 30;
            const int DISTANCE_ITERATIONS = 30;

            float bhatCoeff1 = 0;
            float bhatCoeff2 = 0;
            int dIterations = 0;
            int msIterations = 0;
            float distance = 0;
            Bitmap cropped = null;

            Window _targetRoi = new Window();

            int centreX = _targetRoi.CentreX;
            int centreY = _targetRoi.CentreY;
                        
            //Limit the iterations to a fixed number to avoid performance degradation
            do
            {
                _searchRoi.EnsureLimits();
                //Find candidate model at the region of interest
                _histCand = _imgProc.Create1DHistogram(bitmap, _histTarget.BinCount1, 
                _histTarget.BinCount2, _histTarget.BinCount3, 
                _targetRoi.RegionOfInterest, _searchRoi.RegionOfInterest);

                //Get BC
                bhatCoeff1 = Metric.Evaluate(new BhattacharryyaCoefficient(_histTarget, 
               _histCand));

                //Calculate moments                
                cropped = GetImageSection(bitmap, _targetRoi);//crop the region of 
                interest                
                _moment = new MSMoment(cropped, _histTarget, _histCand);
                                
                //Find the new centre
                centreX = _targetRoi.RegionOfInterest.X + (int)(_moment.FirstMomentX / 
                _moment.ZerothMoment);
                centreY = _targetRoi.RegionOfInterest.Y + (int)(_moment.FirstMomentY / 
                _moment.ZerothMoment);
                
                //Move the roi & search window to the new centroid
                _targetRoi.Offset(centreX - _targetRoi.CentreX, centreY - 
                _targetRoi.CentreY);
                _searchRoi.Offset(centreX - _searchRoi.CentreX, centreY - 
                _searchRoi.CentreY);
                
                //Find candidate model at the new location
                _searchRoi.EnsureLimits();
                _histCand = _imgProc.Create1DHistogram(bitmap, _histTarget.BinCount1, 
                _histTarget.BinCount2, _histTarget.BinCount3, 
                _targetRoi.RegionOfInterest, _searchRoi.RegionOfInterest);

                //Get BC at the new location
                bhatCoeff2 = Metric.Evaluate(new BhattacharryyaCoefficient(_histTarget, 
                _histCand));

                while ((bhatCoeff2 < bhatCoeff1) && (dIterations < DISTANCE_ITERATIONS))
                {
                    centreX = (int)Math.Ceiling(((float)(centreX + _previousCentreX)) / 
                    2);
                    centreY = (int)Math.Ceiling(((float)(centreY + _previousCentreY)) / 
                     2);

                    //Move ROI to the new location
                    _targetRoi.Offset(centreX - _targetRoi.CentreX, centreY - 
                    _targetRoi.CentreY);
                    _searchRoi.Offset(centreX - _searchRoi.CentreX, centreY - 
                    _searchRoi.CentreY);
                                        
                    //Find candidate model at the new location
                    _searchRoi.EnsureLimits();
                    _histCand = _imgProc.Create1DHistogram(bitmap, 
                    _histTarget.BinCount1, _histTarget.BinCount2, 
                    _histTarget.BinCount3, _targetRoi.RegionOfInterest, 
                    _searchRoi.RegionOfInterest);

                    //Get BC at the new location
                    bhatCoeff2 = Metric.Evaluate(new 
                    BhattacharryyaCoefficient(_histTarget, _histCand));

                    dIterations++;
                }

                //Calculate the distance between two vectors
                distance = (float)Math.Sqrt(Math.Pow((centreX - _previousCentreX), 2)
                    + Math.Pow((centreY - _previousCentreY), 2));

                _previousCentreX = centreX;
                _previousCentreY = centreY;

                msIterations++;

            } while ((distance >= 0.1) && (msIterations < MEANSHIFT_ITERATIONS));
                       
            //save info
            //_moment.Information.Clear();
            _moment.Information.Add("Meanshift Iterations: ", msIterations.ToString());
            _moment.Information.Add("Bhattacharyya Coeff: ", bhatCoeff2.ToString());

            //check validity
            if (centreX > 0 && centreY > 0)
            {
                //Move the roi & search window to the new centroid
                _targetRoi.Offset(centreX - _targetRoi.CentreX, centreY - 
                _targetRoi.CentreY);
                _searchRoi.Offset(centreX - _searchRoi.CentreX, centreY - 
                _searchRoi.CentreY);

                _moment.Information.Add("Centroid: ", _targetRoi.CentreX.ToString() + 
                 ", " + _targetRoi.CentreY.ToString());

                //_processedImage = Drawer.DrawMoment(bitmap, _moment, new 
                Point(centreX, centreY));
                _processedImage = Drawer.DrawWindow(bitmap, _targetRoi, Color.Red);
                _processedImage = Drawer.DrawWindow(bitmap, _searchRoi, Color.Yellow);
            }

            //save ROIs for next frame
            targetRoi = _targetRoi;
            searchRoi = _searchRoi;
            information = _moment.Information;
        }

        public virtual Bitmap ProcessedImage
        {
            get { return _processedImage; }
        }

        #endregion

        private Bitmap GetImageSection(Bitmap bmp, Window roi)
        {
            roi.EnsureLimits(); //make sure it is not out of the picture
            //return _imgProc.Crop(bmp, roi.RegionOfInterest);
            return bmp.Clone(roi.RegionOfInterest, bmp.PixelFormat); //select the 
            section            
        }

        protected IProcessor _imgProc = null;
        protected Bitmap _processedImage = null;
        private Histogram _histTarget = null;
        private Histogram _histCand = null;        
        private Window _targetRoi;
        private Window _searchRoi;
        private MSMoment _moment = new MSMoment();
        private int _previousCentreX = 0;
        private int _previousCentreY = 0;
    }
}

change

private Window _targetRoi;

to

private Window _targetRoi = new Window();

and delete the red line.
Try to find out with IntelliSense if the method is in the Window class. Maybe there is a mix up with the Window class (is it your own? Or a .NET one?). You might use a "wrong" class. Hold the mouse on "Window" and check the namespace.

Where did you see

private Window _targetRoi;

I could not find it so I added 'private to

Window _targetRoi = new Window();

in the Track method.

IntelliSense would not allow me to use

private Window _targetRoi = new Window();

It said Invalid expression 'private'

The method is not in the Window class. It's in the CVMeanshift class which is in frmMain.cs I posted that earlier.

I'll keep on playing with it.

Well, I have found the line

private Window _targetRoi;

so you should be able to find it, too.

Try the following:
Find the line (take your time :-) and add the initialization as posted in my previous post.
Do the same for

private Window _searchRoi;

Then replace all occurrences of "Window" with "UIGraphic.Window".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.