I want to track 265 Sequence images which saved in "D:\\Resources\\Sequence"
I get warning that
videoCapture
is never assigned to, and will always have its default value null...and when I run it I get this message "
"Cannot find any camera!"
"...I don't know how to solve this problem..could you help me....thanks
I wrote this code:
What I have tried:
namespace Tracking2
{
public partial class Form1 : Form
{
ImageStreamReader videoCapture;
public Form1()
{
InitializeComponent();
#if FILE_CAPTURE
roi = new Rectangle(115, 220, 30, 15);
isROISelected = true;
#endif
initalizeHistograms();
try
{
#if FILE_CAPTURE
string videoDir = "D:\\Resources\\Sequence";
videoCapture = new ImageDirectoryCapture(videoDir, "*.jpg");
#else
videoCapture = new CameraCapture(0);
#endif
}
catch (Exception)
{
MessageBox.Show("Cannot find any camera!");
return;
}
this.FormClosing += CamshiftDemo_FormClosing;
Application.Idle += videoCapture_InitFrame;
videoCapture.Open();
}
Bgr<byte>[,] frame = null;
void videoCapture_InitFrame(object sender, EventArgs e)
{
videoCapture.ReadTo(ref frame);
if (frame == null)
return;
videoCapture.Seek(-1, SeekOrigin.Current);
if (isROISelected)
{
initTracking(frame);
Application.Idle -= videoCapture_InitFrame;
Application.Idle += videoCapture_NewFrame;
}
else
{
frame.Draw(roi, Bgr<byte>.Blue, 3);
}
this.pictureBox.Image = frame.ToBitmap();
GC.Collect();
}
void videoCapture_NewFrame(object sender, EventArgs e)
{
videoCapture.ReadTo(ref frame);
if (frame == null)
return;
if (!isROISelected)
{
Application.Idle += videoCapture_InitFrame;
Application.Idle -= videoCapture_NewFrame;
return;
}
long start = DateTime.Now.Ticks;
Rectangle prevSearchArea = searchArea;
bool isPredicted = nonVisibleCount > 0;
Gray<byte>[,] probabilityMap;
Box2D foundBox;
trackOneStep(frame, out probabilityMap, out foundBox);
long end = DateTime.Now.Ticks;
long elapsedMs = (end - start) / TimeSpan.TicksPerMillisecond;
frame.Draw("Processed: " + elapsedMs + " ms", font, new Point(25, 20), Bgr<byte>.Green);
this.pictureBox.Image = frame.ToBitmap();
this.pbProbabilityImage.Image = probabilityMap.ToBitmap();
GC.Collect();
System.Threading.Thread.Sleep(25);
}