Пример #1
0
        /// <summary>
        /// grabs a frame from the camera
        /// </summary>
        private static void CaptureFrame(
            Capture cam,
            int initial_frames,
            string output_filename,
            string output_format,
            IntPtr m_ip)
        {
            if (cam != null)
            {
                // start rolling the cameras
                if (cam.lastFrame != null)
                {
                    cam.lastFrame.Dispose();
                }

                if (m_ip != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(m_ip);
                    m_ip = IntPtr.Zero;
                }

                cam.Resume();

                // grab frames
                for (int i = 0; i < initial_frames; i++)
                {
                    cam.Grab(ref m_ip, false);

                    if (m_ip != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(m_ip);
                        m_ip = IntPtr.Zero;
                    }
                }
                Bitmap grabbed_image = cam.Grab(ref m_ip, true);
                if (grabbed_image != null)
                {
                    System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                    output_format = output_format.ToLower();
                    if (output_format == "bmp")
                    {
                        format = System.Drawing.Imaging.ImageFormat.Bmp;
                    }
                    if (output_format == "png")
                    {
                        format = System.Drawing.Imaging.ImageFormat.Png;
                    }
                    if (output_format == "gif")
                    {
                        format = System.Drawing.Imaging.ImageFormat.Gif;
                    }
                    grabbed_image.Save(output_filename + "." + output_format, format);
                }

                // stop the camera
                cam.Stop();
            }
        }
Пример #2
0
        /// <summary>
        /// grabs a frame from the camera
        /// </summary>
        private static void CaptureFrame(
            Capture cam,
            int initial_frames,
            string output_filename,
            string output_format,
            IntPtr m_ip)
        {
            if (cam != null)
            {
                // start rolling the cameras
                if (cam.lastFrame != null)
                    cam.lastFrame.Dispose();

                if (m_ip != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(m_ip);
                    m_ip = IntPtr.Zero;
                }

                cam.Resume();

                // grab frames                
                for (int i = 0; i < initial_frames; i++)
                {
                    cam.Grab(ref m_ip, false);

                    if (m_ip != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(m_ip);
                        m_ip = IntPtr.Zero;
                    }
                }
                Bitmap grabbed_image = cam.Grab(ref m_ip, true);
                if (grabbed_image != null)
                {
                    System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                    output_format = output_format.ToLower();
                    if (output_format == "bmp") format = System.Drawing.Imaging.ImageFormat.Bmp;
                    if (output_format == "png") format = System.Drawing.Imaging.ImageFormat.Png;
                    if (output_format == "gif") format = System.Drawing.Imaging.ImageFormat.Gif;
                    grabbed_image.Save(output_filename + "." + output_format, format);
                }

                // stop the camera
                cam.Stop();
            }
        }
Пример #3
0
        /// <summary>
        /// grabs frames from two cameras
        /// </summary>
        private static void CaptureFrames(
            Capture cam0,
            Capture cam1,
            int initial_frames,
            string output_filename,
            string output_format,
            IntPtr m_ip0,
            IntPtr m_ip1)
        {
            const int step_size = 5; // when checking if frames are blank

            if ((cam0 != null) && (cam1 != null))
            {
                /*
                if (m_ip0 != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(m_ip0);
                    m_ip0 = IntPtr.Zero;
                }
                
                if (m_ip1 != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(m_ip1);
                    m_ip1 = IntPtr.Zero;
                }
                 */

                for (int i = 0; i < 2; i++)
                {
                    Capture cam = cam0;
                    if (i > 0) cam = cam1;

                    // start rolling the cameras
                    if (cam.lastFrame != null)
                        cam.lastFrame.Dispose();

                    cam.Resume();
                }

                // grab frames       
                Bitmap grabbed_image0 = null;
                Bitmap grabbed_image1 = null;
                bool is_blank0 = true;
                bool is_blank1 = true;
                Parallel.For(0, 2, delegate(int j)
                {
                    for (int i = 0; i < initial_frames + 1; i++)
                    {

                        if (j == 0)
                        {
                            /*
                            if (m_ip0 != IntPtr.Zero)
                            {
                                Marshal.FreeCoTaskMem(m_ip0);
                                m_ip0 = IntPtr.Zero;
                            }
                             */

                            grabbed_image0 = cam0.Grab(ref m_ip0, true);
                            is_blank0 = IsBlankFrame(grabbed_image0, step_size);
                            if (!is_blank0) break;
                        }
                        else
                        {
                            /*
                            if (m_ip1 != IntPtr.Zero)
                            {
                                Marshal.FreeCoTaskMem(m_ip1);
                                m_ip1 = IntPtr.Zero;
                            }
                             */

                            grabbed_image1 = cam1.Grab(ref m_ip1, true);
                            is_blank1 = IsBlankFrame(grabbed_image1, step_size);
                            if (!is_blank1) break;
                        }
                    }
                } );

                if ((grabbed_image0 != null) &&
                    (grabbed_image1 != null))
                {
                    System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                    output_format = output_format.ToLower();
                    if (output_format == "bmp") format = System.Drawing.Imaging.ImageFormat.Bmp;
                    if (output_format == "png") format = System.Drawing.Imaging.ImageFormat.Png;
                    if (output_format == "gif") format = System.Drawing.Imaging.ImageFormat.Gif;
                    grabbed_image0.Save(output_filename + "0." + output_format, format);
                    grabbed_image1.Save(output_filename + "1." + output_format, format);
                }

                for (int i = 0; i < 2; i++)
                {
                    Capture cam = cam0;
                    if (i > 0) cam = cam1;

                    // stop the camera
                    cam.Stop();
                }
            }
        }
Пример #4
0
        /// <summary>
        /// grabs frames from two cameras
        /// </summary>
        private static void CaptureFrames(
            Capture cam0,
            Capture cam1,
            int initial_frames,
            string output_filename,
            string output_format,
            IntPtr m_ip0,
            IntPtr m_ip1)
        {
            const int step_size = 5; // when checking if frames are blank

            if ((cam0 != null) && (cam1 != null))
            {
                /*
                 * if (m_ip0 != IntPtr.Zero)
                 * {
                 *  Marshal.FreeCoTaskMem(m_ip0);
                 *  m_ip0 = IntPtr.Zero;
                 * }
                 *
                 * if (m_ip1 != IntPtr.Zero)
                 * {
                 *  Marshal.FreeCoTaskMem(m_ip1);
                 *  m_ip1 = IntPtr.Zero;
                 * }
                 */

                for (int i = 0; i < 2; i++)
                {
                    Capture cam = cam0;
                    if (i > 0)
                    {
                        cam = cam1;
                    }

                    // start rolling the cameras
                    if (cam.lastFrame != null)
                    {
                        cam.lastFrame.Dispose();
                    }

                    cam.Resume();
                }

                // grab frames
                Bitmap grabbed_image0 = null;
                Bitmap grabbed_image1 = null;
                bool   is_blank0      = true;
                bool   is_blank1      = true;
                Parallel.For(0, 2, delegate(int j)
                {
                    for (int i = 0; i < initial_frames + 1; i++)
                    {
                        if (j == 0)
                        {
                            /*
                             * if (m_ip0 != IntPtr.Zero)
                             * {
                             *  Marshal.FreeCoTaskMem(m_ip0);
                             *  m_ip0 = IntPtr.Zero;
                             * }
                             */

                            grabbed_image0 = cam0.Grab(ref m_ip0, true);
                            is_blank0      = IsBlankFrame(grabbed_image0, step_size);
                            if (!is_blank0)
                            {
                                break;
                            }
                        }
                        else
                        {
                            /*
                             * if (m_ip1 != IntPtr.Zero)
                             * {
                             *  Marshal.FreeCoTaskMem(m_ip1);
                             *  m_ip1 = IntPtr.Zero;
                             * }
                             */

                            grabbed_image1 = cam1.Grab(ref m_ip1, true);
                            is_blank1      = IsBlankFrame(grabbed_image1, step_size);
                            if (!is_blank1)
                            {
                                break;
                            }
                        }
                    }
                });

                if ((grabbed_image0 != null) &&
                    (grabbed_image1 != null))
                {
                    System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                    output_format = output_format.ToLower();
                    if (output_format == "bmp")
                    {
                        format = System.Drawing.Imaging.ImageFormat.Bmp;
                    }
                    if (output_format == "png")
                    {
                        format = System.Drawing.Imaging.ImageFormat.Png;
                    }
                    if (output_format == "gif")
                    {
                        format = System.Drawing.Imaging.ImageFormat.Gif;
                    }
                    grabbed_image0.Save(output_filename + "0." + output_format, format);
                    grabbed_image1.Save(output_filename + "1." + output_format, format);
                }

                for (int i = 0; i < 2; i++)
                {
                    Capture cam = cam0;
                    if (i > 0)
                    {
                        cam = cam1;
                    }

                    // stop the camera
                    cam.Stop();
                }
            }
        }