コード例 #1
0
        /// <summary>
        ///     Adds an image file from bytes array to output folder.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnImageRecieved(object sender, ImageReceivedEventArgs e)
        {
            string newImagePath = _tempOutputFolder + e.ImageName;

            // Saves a temp image copy to a temp directory, adds it to the output folder and deletes temp copy.

            Directory.CreateDirectory(_tempOutputFolder);
            File.WriteAllBytes(newImagePath, e.Bytes);
            AddFile(newImagePath, out EventLogEntryType _);
            File.Delete(newImagePath);

            // Removes temp directory
            if (Directory.GetFiles(_tempOutputFolder).Length == 0)
            {
                Directory.Delete(_tempOutputFolder);
            }
        }
コード例 #2
0
ファイル: Camera.cs プロジェクト: tcboy88/touchcam
        /// <summary>
        /// Called every time a new frame shows up from the camera
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void provider_ImageTransaction(object sender, ImageReceivedEventArgs e)
        {
            if (stopping || e == null || e.PixelData == null)
            {
                return;
            }

            if (Monitor.TryEnter(this))
            {
                imgGPU.Scatter(e.PixelData);

                if (calibrating)
                {
                    // compute a running mean of each pixel
                    worker.Launch(RunningMean_Kernel, lp, e.Width, imgGPU.Ptr, meanImg.Ptr, numCalibrationSamples);
                    numCalibrationSamples++;

                    // compute the mean over the full mean image, using a reduction operation
                    addReduce.Reduce(meanImg.Ptr, scalarOutput.Ptr, numPixels);
                    var mean = scalarOutput.GatherScalar();
                    mean /= numPixels;

                    // update the correction factor for each pixel
                    worker.Launch(UpdateCorrectionFactor_Kernel, lp, e.Width, meanImg.Ptr, correctionFactor.Ptr, mean);
                }

                if (correctBrightness)
                {
                    worker.Launch(ApplyCorrectionFactor_Kernel, lp, e.Width, correctionFactor.Ptr, imgGPU.Ptr);
                    imgGPU.Gather(e.PixelData);
                }

                img.Bytes = e.PixelData; // note: have to do this last, because if you set it earlier but then modify the bytes it won't update the image

                // trigger a new frame event
                OnFrameAvailable(new VideoFrame {
                    Image = img, ImageGPU = imgGPU, Timestamp = e.TimeStamp
                });

                Monitor.Exit(this);
            }
        }
コード例 #3
0
        /// <summary>
        /// Called every time a new frame shows up from the camera
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void provider_ImageTransaction(object sender, ImageReceivedEventArgs e)
        {
            if (stopping || e == null || e.PixelData == null)
            {
                return;
            }

            if (Monitor.TryEnter(this))
            {
                try
                {
                    Bitmap bmp = ArrayToBitmap(e.PixelData, e.Width, e.Height, PixelFormat.Format8bppIndexed);

                    // trigger a new frame event
                    OnFrameAvailable(bmp);
                }
                catch (Exception ex) { Debug.WriteLine("Error receiving image from camera: " + ex.ToString()); }

                Monitor.Exit(this);
            }
        }
コード例 #4
0
 private void OnRaiseImageReceivedEvent(ImageReceivedEventArgs imageReceivedEventArgs)
 {
     ImageReceivedEventArgs?.Invoke(this, imageReceivedEventArgs);
 }