Пример #1
0
        private void PopulateStreamFormat()
        {
            lblColorSpace.Text = CameraLang.FormConfiguration_Properties_StreamFormat;

            // Get the intersection of camera and Kinovea supported formats.
            List <IDSEnum> streamFormats = IDSHelper.GetSupportedStreamFormats(camera, deviceId);

            // Get currently selected option.
            int currentColorMode = IDSHelper.ReadCurrentStreamFormat(camera);

            cmbFormat.Items.Clear();

            foreach (IDSEnum streamFormat in streamFormats)
            {
                cmbFormat.Items.Add(streamFormat);
                if (streamFormat.Value == currentColorMode)
                {
                    selectedStreamFormat    = streamFormat;
                    cmbFormat.SelectedIndex = cmbFormat.Items.Count - 1;
                }
            }

            // TODO: if the current camera format is not supported in Kinovea, force the camera to switch to a supported mode.
            // What if none of the Kinovea modes are supported by the camera ?
        }
Пример #2
0
        /// <summary>
        /// Configure device and report frame format that will be used during streaming.
        /// This method must return a proper ImageDescriptor so we can pre-allocate buffers.
        /// </summary>
        public ImageDescriptor Prepare()
        {
            Open();

            if (!camera.IsOpened)
            {
                return(ImageDescriptor.Invalid);
            }

            firstOpen = false;

            ImageFormat format = IDSHelper.GetImageFormat(camera);

            // FIXME: Force a supported format if the current one is unsuitable.
            if (format == ImageFormat.None)
            {
                return(ImageDescriptor.Invalid);
            }

            // FIXME: RGB24 should allocate buffers aligned to 4 bytes.
            // It is usually the case because none of the UI let the user choose a non aligned width.
            Rectangle rect;

            camera.Size.AOI.Get(out rect);
            incomingBufferSize = ImageFormatHelper.ComputeBufferSize(rect.Width, rect.Height, format);
            incomingBuffer     = new byte[incomingBufferSize];

            resultingFramerate = IDSHelper.GetFramerate(camera);
            int width  = rect.Width;
            int height = rect.Height;

            finishline.Prepare(width, height, format, resultingFramerate);
            if (finishline.Enabled)
            {
                height             = finishline.Height;
                resultingFramerate = finishline.ResultingFramerate;
            }

            int  outgoingBufferSize = ImageFormatHelper.ComputeBufferSize(width, height, format);
            bool topDown            = true;

            resultingFramerate = IDSHelper.GetFramerate(camera);

            return(new ImageDescriptor(format, width, height, topDown, outgoingBufferSize));
        }
Пример #3
0
        private void Open()
        {
            // Unlike in the DirectShow module, we do not backup and restore camera configuration.
            // If the user configured the camera outside of Kinovea we respect the new settings.
            // Two reasons:
            // 1. In DirectShow we must do the backup/restore to work around drivers that inadvertently reset the camera properties.
            // 2. Industrial cameras have many properties that won't be configurable in Kinovea
            // so the user is more likely to configure the camera from the outside.

            if (grabbing)
            {
                Stop();
            }

            try
            {
                uEye.Defines.Status status = camera.Init((Int32)deviceId | (Int32)uEye.Defines.DeviceEnumeration.UseDeviceID);

                if (status != uEye.Defines.Status.SUCCESS)
                {
                    log.ErrorFormat("Error trying to open IDS uEye camera.");
                    return;
                }

                // Load parameter set.
                ProfileHelper.Load(camera, summary.Identifier);
            }
            catch (Exception e)
            {
                log.Error("Could not open IDS uEye camera.", e);
                return;
            }

            SpecificInfo specific = summary.Specific as SpecificInfo;

            if (specific == null)
            {
                return;
            }

            // Store the camera object into the specific info so that we can retrieve device informations from the configuration dialog.
            specific.Camera = camera;

            int currentColorMode = IDSHelper.ReadCurrentStreamFormat(camera);

            // Some properties can only be changed when the camera is opened but not streaming. Now is the time.
            // We store them in the summary when coming back from FormConfiguration, and we write them to the camera here.
            // Only do this if it's not the first time we open the camera, to respect any change that could have been done outside Kinovea.
            if (firstOpen)
            {
                specific.StreamFormat = currentColorMode;
            }
            else
            {
                if (specific.StreamFormat != currentColorMode)
                {
                    IDSHelper.WriteStreamFormat(camera, specific.StreamFormat);
                }

                CameraPropertyManager.WriteCriticalProperties(camera, specific.CameraProperties);

                // Save parameter set.
                ProfileHelper.Save(camera, ProfileHelper.GetProfileFilename(summary.Identifier));
            }

            // Reallocate IDS internal buffers after changing the format.
            Int32[] memList;
            camera.Memory.GetList(out memList);
            camera.Memory.Free(memList);
            camera.Memory.Allocate();

            int memId;

            camera.Memory.GetActive(out memId);

            int width, height, bitsPerPixel, pitch;

            camera.Memory.Inquire(memId, out width, out height, out bitsPerPixel, out pitch);

            log.DebugFormat("IDS internal buffers allocated: {0}x{1}, {2} bits per pixel, pitch:{3}.", width, height, bitsPerPixel, pitch);
        }