Ejemplo n.º 1
0
 public byte[] ReadFrame(VisionImage image, UInt32 frame, bool readData)
 {
     ThrowIfDisposed();
     if (image == null)
     {
         throw new ArgumentNullException("image");
     }
     image.ThrowIfDisposed();
     if (readData)
     {
         UInt32 dataSize = MaximumDataSize;
         byte[] tempData = new byte[dataSize];
         Utilities.ThrowError(VisionDllCommon.imaqReadAVIFrame(image._image, _session, frame, tempData, ref dataSize));
         byte[] data = tempData;
         if (dataSize != MaximumDataSize)
         {
             data = new byte[dataSize];
             Array.Copy(tempData, data, dataSize);
         }
         return(data);
     }
     else
     {
         Utilities.ThrowError(VisionDllCommon.imaqReadAVIFrame(image._image, _session, frame, IntPtr.Zero, IntPtr.Zero));
         return(null);
     }
 }
Ejemplo n.º 2
0
        //==========================================================================================
        /// <summary>
        /// Changes the type of an image with the specified source, destination, type, and lookup table.
        /// </summary>
        /// <param name="source">
        /// The source image.
        /// </param>
        /// <param name="destination">
        /// The destination image. Set this parameter equal to source or <see langword="null"/> to perform the change directly on the source image.
        /// </param>
        /// <param name="type">
        /// The new type for the image. <paramref name="type"/> is the new type for the <paramref name="destination"/> image if it is being used, otherwise it is the new type for <paramref name="source"/>.
        /// </param>
        /// <param name="lookupTable">
        /// An optional lookup table. If you do not want  to use a lookup table, this parameter may be <see keyword="" keywordType="mstudio"/>.
        /// </param>

        public static void Cast(VisionImage source, VisionImage destination, ImageType type, Collection <float> lookupTable)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            source.ThrowIfDisposed();
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            destination.ThrowIfDisposed();
            int tableSize = 256;

            if (source.Type == ImageType.I16 || source.Type == ImageType.U16)
            {
                tableSize = 65536;
            }
            // If the table is the correct size, just do the conversion; otherwise, pad it first.
            float[] cviTable;
            if (lookupTable == null)
            {
                cviTable = null;
            }
            else
            {
                if (lookupTable.Count >= tableSize)
                {
                    cviTable = Utilities.ConvertCollectionToArray <float>(lookupTable);
                }
                else
                {
                    cviTable = new float[tableSize];
                    for (int i = 0; i < lookupTable.Count; ++i)
                    {
                        cviTable[i] = lookupTable[i];
                    }
                    for (int i = lookupTable.Count; i < tableSize; ++i)
                    {
                        if (source.Type == ImageType.I16)
                        {
                            cviTable[i] = (i <= 32768) ? (float)i : (float)(i - 65536);
                        }
                        else
                        {
                            cviTable[i] = i;
                        }
                    }
                }
            }
            Utilities.ThrowError(VisionDllCommon.imaqCast(destination._image, source._image, type, cviTable, 0));
        }
Ejemplo n.º 3
0
        //==========================================================================================
        /// <summary>
        /// Copies the source image to the destination image, including the border size and calibration information.
        /// </summary>
        /// <param name="source">
        /// The source image to copy.
        /// </param>
        /// <param name="destination">
        /// The resulting image.
        /// </param>
        /// <remarks>
        /// Use this method with all image types.
        /// <para>
        /// To copy an area of one image to an area of another image, use the Extract2 method with xSubsample and ySubsample set to 1.
        /// </para>
        ///     <para>
        /// The <paramref name="source"/> and <paramref name="destination"/> images must be the same type of image. The method copies the complete definition of the source image and its pixel data to the destination image. The method also modifies the border of the destination image so that it becomes the same size as the border of the source image.
        /// </para>
        /// </remarks>

        public static void Copy(VisionImage source, VisionImage destination)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            source.ThrowIfDisposed();
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            destination.ThrowIfDisposed();
            Utilities.ThrowError(VisionDllCommon.imaqDuplicate(destination._image, source._image));
        }
Ejemplo n.º 4
0
        //==========================================================================================
        /// <summary>
        /// Changes the type of an image with the specified source, destination, type, and shifts.
        /// </summary>
        /// <param name="source">
        /// The source image.
        /// </param>
        /// <param name="destination">
        /// The destination image. Set this parameter equal to source or <see langword="null"/> to perform the change directly on the source image.
        /// </param>
        /// <param name="type">
        /// The new type for the image. <paramref name="type"/> is the new type for the <paramref name="destination"/> image if it is being used, otherwise it is the new type for <paramref name="source"/>.
        /// </param>
        /// <param name="numberOfShifts">
        /// The shift value for converting 16-bit images to 8-bit images. The method executes this conversion by shifting the 16-bit pixel values to the right by the specified number of shift operations, up to a maximum of 8 shift operations, and then truncating to get an 8-bit value. Enter a value of –1 to ignore the bit depth and shift 0. Enter a value of 0 to use the bit depth to cast the image.
        /// </param>

        public static void Cast(VisionImage source, VisionImage destination, ImageType type, Int32 numberOfShifts)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            source.ThrowIfDisposed();
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            destination.ThrowIfDisposed();
            Utilities.ThrowError(VisionDllCommon.imaqCast(destination._image, source._image, type, null, numberOfShifts));
        }
Ejemplo n.º 5
0
        //==========================================================================================
        /// <summary>
        /// Writes a frame to the currently open Audio Video Interleave (AVI) file with the specified image and data.
        /// </summary>
        /// <param name="image">
        /// The image to write to the frame of the AVI.
        /// </param>
        /// <param name="data">
        /// The data to attach to this frame, if any.
        /// </param>

        public void WriteFrame(VisionImage image, byte[] data)
        {
            ThrowIfDisposed();
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            image.ThrowIfDisposed();
            if (data == null)
            {
                Utilities.ThrowError(VisionDllCommon.imaqWriteAVIFrame(image._image, _session, IntPtr.Zero, 0));
            }
            else
            {
                Utilities.ThrowError(VisionDllCommon.imaqWriteAVIFrame(image._image, _session, data, (UInt32)data.Length));
            }
        }