Ejemplo n.º 1
0
        void acquisitionWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;

            // Keep acquiring until we error or cancel
            while (!worker.CancellationPending)
            {
                try
                {
                    // Grab the next image
                    uint bufNum;
                    _session.Grab(imageViewer.Image, true, out bufNum);

                    // Report our buffer number acquired
                    worker.ReportProgress(0, bufNum);
                }
                catch (ImaqdxException exception)
                {
                    // If we have been stopped, ignore the exception since
                    // it is likely just an error indicating the acquisition has
                    // been stopped
                    if (!worker.CancellationPending)
                    {
                        e.Result = exception;
                    }
                    return;
                }
            }
        }
Ejemplo n.º 2
0
 private void stream()
 {
     image = new VisionImage();
     try
     {
         imaqdxSession.ConfigureGrab();
     }
     catch (ObjectDisposedException e)
     {
         MessageBox.Show(e.Message);
         return;
     }
     for (; ;)
     {
         lock (streamStopLock)
         {
             try
             {
                 imaqdxSession.Grab(image, true);
                 if (analyse)
                 {
                     PixelValue2D pval = image.ImageToArray();
                     byte[,] u8array = Getthearray.convertToU8(pval.Rgb32);
                     max             = Getthearray.Findthemaximum(u8array);
                     imageWindow.WriteToConsole(max.ToString("F6"));
                 }
             }
             catch (InvalidOperationException e)
             {
                 MessageBox.Show("Something bad happened. Stopping the image stream.\n" + e.Message);
                 state = CameraState.FREE;
                 return;
             }
             try
             {
                 if (windowShowing)
                 {
                     imageWindow.AttachToViewer(image);
                 }
             }
             catch (InvalidOperationException e)
             {
                 MessageBox.Show("I have a leftover image without anywhere to display it. Dumping...\n\n" + e.Message);
                 imaqdxSession.Acquisition.Stop();
                 state = CameraState.FREE;
                 return;
             }
             if (state != CameraState.STREAMING)
             {
                 imaqdxSession.Acquisition.Stop();
                 state = CameraState.FREE;
                 return;
             }
         }
     }
 }
Ejemplo n.º 3
0
 private void stream()
 {
     image = new VisionImage();
     try
     {
         imaqdxSession.ConfigureGrab();
     }
     catch (ObjectDisposedException e)
     {
         MessageBox.Show(e.Message);
         return;
     }
     for (; ;)
     {
         lock (streamStopLock)
         {
             try
             {
                 imaqdxSession.Grab(image, true);
             }
             catch (InvalidOperationException e)
             {
                 MessageBox.Show("Something bad happened. Stopping the image stream.\n" + e.Message);
                 state = CameraState.FREE;
                 return;
             }
             try
             {
                 if (windowShowing)
                 {
                     imageWindow.AttachToViewer(image);
                 }
             }
             catch (InvalidOperationException e)
             {
                 MessageBox.Show("I have a leftover image without anywhere to display it. Dumping...\n\n" + e.Message);
                 imaqdxSession.Acquisition.Stop();
                 state = CameraState.FREE;
                 return;
             }
             if (state != CameraState.STREAMING)
             {
                 imaqdxSession.Acquisition.Stop();
                 state = CameraState.FREE;
                 return;
             }
         }
     }
 }
Ejemplo n.º 4
0
        public void GrabThread()
        {
            while (bFly)
            {
                if (bPause)
                {
                    Thread.Sleep(1);
                    continue;
                }

                try
                {
                    VisionImage image = new VisionImage();
                    _session.Grab(Form_Main.Instance.imageSet.Image, true);
                    Algorithms.Copy(Form_Main.Instance.imageSet.Image, image);
                    this.GrabList.Add(image);
                    //Form_Main.Instance.X.GetAxisPos();
                    //Debug.WriteLine($"X:{Form_Main.Instance.X.Pos}\r\n");
                }
                catch { }
            }
        }
Ejemplo n.º 5
0
        private void stream()
        {
            ushort[,] latestdata;

            double summedPixels = 0;

            SummedPixels = 0;
            image        = new VisionImage();
            try
            {
                imaqdxSession.ConfigureGrab();
            }
            catch (ObjectDisposedException e)
            {
                MessageBox.Show(e.Message);
                return;
            }
            for (; ;)
            {
                lock (streamStopLock)
                {
                    try
                    {
                        imaqdxSession.Grab(image, true);
                    }
                    catch (InvalidOperationException e)
                    {
                        MessageBox.Show("Something bad happened. Stopping the image stream.\n" + e.Message);
                        state = CameraState.FREE;
                        return;
                    }
                    try
                    {
                        if (windowShowing)
                        {
                            imageWindow.AttachToViewer(image);

                            if (imageWindow.imageViewer.Roi != null)
                            {
                                RectangleContour contour = imageWindow.imageViewer.Roi.GetBoundingRectangle();
                                int          height      = (int)contour.Height;
                                int          width       = (int)contour.Width;
                                PixelValue2D pval        = image.ImageToArray(contour);

                                if (image.Type == ImageType.U8)
                                {
                                    ushort[,] ushortData = new ushort[pval.U8.GetLength(0), pval.U8.GetLength(1)];
                                    for (int j = 0; j < pval.U8.GetLength(0); j++)
                                    {
                                        for (int i = 0; i < pval.U8.GetLength(1); i++)
                                        {
                                            ushortData[j, i] = (pval.U8)[j, i];
                                        }
                                    }
                                    latestdata = ushortData;
                                }
                                else
                                {
                                    latestdata = pval.U16;
                                }

                                summedPixels = 0;
                                for (int i = 0; i < width; i++)
                                {
                                    for (int j = 0; j < height; j++)
                                    {
                                        summedPixels = summedPixels + latestdata[j, i];
                                    }
                                }
                                SummedPixels = summedPixels;
                            }
                        }
                    }
                    catch (InvalidOperationException e)
                    {
                        MessageBox.Show("I have a leftover image without anywhere to display it. Dumping...\n\n" + e.Message);
                        imaqdxSession.Acquisition.Stop();
                        state = CameraState.FREE;
                        return;
                    }
                    if (state != CameraState.STREAMING)
                    {
                        imaqdxSession.Acquisition.Stop();
                        state = CameraState.FREE;
                        return;
                    }
                }
            }
        }