Click here to Skip to main content
15,944,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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); //user defined rectangle for    sample video
            isROISelected = true;
            #endif
            initalizeHistograms(); //create histograms

            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);
        }
Posted
Updated 19-Oct-19 10:29am
Comments
F-ES Sitecore 16-Oct-19 11:33am    
If the "try" code in Form1() fails and it drops into the catch there is a change that videoCapture will remain unassigned. That's probably the source of the warning, and you could fix that by adding "videoCapture = null;" before the "return" in the catch block.

I doubt that will fix your problem about not finding the camera though.

1 solution

If you want to work without a camera and only with files, use this as the first line in your code:
#DEFINE FILE_CAPTURE

You probably also need this line:
ImageStreamReader videoCapture;

Also see: #define - C# Reference | Microsoft Docs[^]
And: Introducing Portable Imaging IO Library for C#[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900