Beispiel #1
0
    /// <summary>
    /// Called on initialization
    /// </summary>
    private void Awake()
    {
        Instance = this;

        // 解析モードと学習モードを切り替えるフラグの設定
        AppMode = AppModes.Analysis;
    }
Beispiel #2
0
 private void Consume()
 {
     try
     {
         while (true)
         {
             ImageCapture thisImage = null;
             if (_queue.TryDequeue(out thisImage))
             {
                 Dispatcher.Invoke(new Action(() =>
                 {
                     _currentState.HandleEvent(thisImage.CaptureType == CaptureType.PREVIEW ? EventType.PREVIEW_IMAGE_ARRIVED : EventType.IMAGE_CAPTURED, thisImage.Image);
                     //if (_readyForCapture)
                     //{
                     //_readyForCapture = false;
                     //_currentState.HandleEvent(EventType.IMAGE_CAPTURED, thisImage);
                     //}
                 }));
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
        async public virtual System.Threading.Tasks.Task TakePictureAsync(ImageCapture param)
        {
            try
            {
                CameraCaptureUI cam  = new CameraCaptureUI();
                var             file = await cam.CaptureFileAsync(CameraCaptureUIMode.Photo);

                using (var stream = await file.OpenReadAsync())
                {
                    byte[] bytes = new byte[stream.Size];
                    using (var reader = new DataReader(stream))
                    {
                        await reader.LoadAsync((uint)stream.Size);

                        reader.ReadBytes(bytes);
                    }


                    if (file != null)
                    {
                        param.ImagePath        = file.Path;
                        param.ImageBinary      = Convert.ToBase64String(bytes);
                        param.CaseServiceRecId = _task.CaseServiceRecID;
                    }
                }
            }
            catch (Exception ex)
            {
                AppSettings.Instance.ErrorMessage = ex.Message;
            }
        }
Beispiel #4
0
    /// <summary>
    /// Called on initialization
    /// </summary>
    private void Awake()
    {
        Instance = this;

        // Change this flag to switch between Analysis Mode and Training Mode
        AppMode = AppModes.Training;
    }
    private void Awake()
    {
        // Allows this instance to behave like a singleton
        instance = this;

        ConsoleOut.SendText("Awake Image Capture");
    }
Beispiel #6
0
    // Return the found image of interest closest to the cursor
    public ImageCapture SelectImage(Vector2 curPos)
    {
        List <ImageCapture> possibleSelections = new List <ImageCapture>();

        if (imagesFound.Count > 0)
        {
            foreach (ImageCapture img in imagesFound)
            {
                if ((curPos.x < img.bottomRightCorner.x) && (curPos.x > img.topLeftCorner.x) && (curPos.y < img.topLeftCorner.y) && (curPos.y > img.bottomRightCorner.y))
                {
                    possibleSelections.Add(img);
                }
            }
        }

        ImageCapture closestImage = null;

        if (possibleSelections.Count > 0)
        {
            closestImage = possibleSelections[0];
            float closestDistance = Mathf.Abs((curPos - possibleSelections[0].GetCenter()).magnitude);

            foreach (ImageCapture img in possibleSelections)
            {
                if (Mathf.Abs((curPos - possibleSelections[0].GetCenter()).magnitude) < closestDistance)
                {
                    closestImage    = img;
                    closestDistance = Mathf.Abs((curPos - possibleSelections[0].GetCenter()).magnitude);
                }
            }
        }

        return(closestImage);
    }
    /// <summary>
    /// Called on initialization
    /// </summary>
    private void Awake()
    {
        Instance = this;

        // Change this flag to switch between Analysis, Training or Smart Mode
        AppMode = AppModes.Analysis;
    }
Beispiel #8
0
 // Start is called before the first frame update
 void Start()
 {
     this._imageProcessor = GetComponent <ImageProcessor>();
     this._imageCapture   = GetComponent <ImageCapture>();
     //this.testScript = GetComponent<TestScript>();
     this.displayPanelInfo = GetComponent <DisplayPanelPosition>();
     this.debug            = GetComponent <Debugger>();
 }
Beispiel #9
0
        public Bitmap CaptureImage()
        {
            Bitmap b = new Bitmap(1, 1);

            //Full screen capture
            if (processCaptureIndex < 0)
            {
                Screen    selected_screen = Screen.AllScreens[-processCaptureIndex - 1];
                Rectangle screenRect      = selected_screen.Bounds;

                screenRect.Width  = (int)(screenRect.Width * scalingValueFloat);
                screenRect.Height = (int)(screenRect.Height * scalingValueFloat);

                Point screenCenter = new Point(screenRect.Width / 2, screenRect.Height / 2);

                //Change size according to selected crop
                screenRect.Width  = (int)(imageCaptureInfo.crop_coordinate_right - imageCaptureInfo.crop_coordinate_left);
                screenRect.Height = (int)(imageCaptureInfo.crop_coordinate_bottom - imageCaptureInfo.crop_coordinate_top);

                //Compute crop coordinates and width/ height based on resolution
                ImageCapture.SizeAdjustedCropAndOffset(screenRect.Width, screenRect.Height, ref imageCaptureInfo);

                //Adjust for crop offset
                imageCaptureInfo.center_of_frame_x += imageCaptureInfo.crop_coordinate_left;
                imageCaptureInfo.center_of_frame_y += imageCaptureInfo.crop_coordinate_top;

                //Adjust for selected screen offset
                imageCaptureInfo.center_of_frame_x += selected_screen.Bounds.X;
                imageCaptureInfo.center_of_frame_y += selected_screen.Bounds.Y;

                b = ImageCapture.CaptureFromDisplay(ref imageCaptureInfo, useResize: true);
            }
            else
            {
                IntPtr handle = new IntPtr(0);

                if (processCaptureIndex >= processList.Length)
                {
                    return(b);
                }

                if (processCaptureIndex != -1)
                {
                    handle = processList[processCaptureIndex].MainWindowHandle;
                }
                //Capture from specific process
                processList[processCaptureIndex].Refresh();
                if ((int)handle == 0)
                {
                    return(b);
                }

                b = ImageCapture.PrintWindow(handle, ref imageCaptureInfo, useCrop: true, useResize: true);
            }

            return(b);
        }
Beispiel #10
0
        protected async System.Threading.Tasks.Task TakeSnapshotAsync <T>(T list, string fieldName) where T : ObservableCollection <ImageCapture>
        {
            try
            {
                CameraCaptureUI ccui        = new CameraCaptureUI();
                var             storagefile = await ccui.CaptureFileAsync(CameraCaptureUIMode.Photo);

                if (storagefile != null)
                {
                    var ms = await RenderDataStampOnSnap.RenderStaticTextToBitmap(storagefile);

                    var    msrandom = new MemoryRandomAccessStream(ms);
                    Byte[] bytes    = new Byte[ms.Length];
                    await ms.ReadAsync(bytes, 0, (int)ms.Length);

                    // StorageFile file = await KnownFolders.PicturesLibrary.CreateFileAsync("Image.png", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

                    StorageFile file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(DateTime.Now.Ticks.ToString() + storagefile.Name, CreationCollisionOption.ReplaceExisting);

                    using (var strm = await file.OpenStreamForWriteAsync())
                    {
                        await strm.WriteAsync(bytes, 0, bytes.Length);

                        strm.Flush();
                    }

                    var ic = new ImageCapture
                    {
                        ImagePath        = file.Path,
                        ImageBinary      = Convert.ToBase64String(bytes),
                        CaseServiceRecId = ((BaseModel)this.Model).VehicleInsRecID,
                        FileName         = string.Format("{0}_{1}", fieldName, list.Count + 1)
                    };
                    list.Add(ic);

                    var imageTable = await SqliteHelper.Storage.LoadTableAsync <ImageCapture>();

                    var dbIC = imageTable.SingleOrDefault(x => x.CaseServiceRecId == ic.CaseServiceRecId && x.FileName == string.Format("{0}_{1}", fieldName, list.Count + 1));
                    if (dbIC == null)
                    {
                        await SqliteHelper.Storage.InsertSingleRecordAsync <ImageCapture>(ic);
                    }
                    else
                    {
                        dbIC.ImagePath   = ic.ImagePath;
                        dbIC.ImageBinary = ic.ImageBinary;
                        await SqliteHelper.Storage.UpdateSingleRecordAsync <ImageCapture>(dbIC);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #11
0
        private void RecognizeImage(RecognizeImageRequest req)
        {
            ImageCapture capture = new ImageCapture
            {
                tag         = req.Tag,
                captureTime = DateTime.Now, // TODO: Get this from the request
                image       = Mat.FromImageData(Convert.FromBase64String(req.ImageBase64))
            };

            _faceCrop.Post(capture);
        }
Beispiel #12
0
        private void OnVideoCapture(Mat image)
        {
            ImageCapture capture = new ImageCapture
            {
                tag         = "",
                captureTime = DateTime.Now,
                image       = image.Clone()
            };

            _faceCrop.Post(capture);
        }
        public MainPageViewModel()
        {
            _imageCapture = new ImageCapture();
            _client       = new EmotionServiceClient("[Your API key here]");

            #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            _imageCapture.InitializeAsync();
            #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            CanTakePicture = true;
        }
Beispiel #14
0
        private void OnMultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs multiSourceFrameArrivedEventArgs)
        {
            if (_queue.Count < _maxQueueSize && _frameRateMinder.canGrabNewFrame())
            {
                ImageCapture capture = _frameManager.ProcessMultiSourceFrameEvent(multiSourceFrameArrivedEventArgs);

                if (capture != null)
                {
                    _queue.Enqueue(capture);
                }
            }
        }
Beispiel #15
0
            public ImageCapture BuildImageCapture(Box dimensions, byte[] data, bool highQuality)
            {
                ImageCapture returnValue = null;

                if (data != null && dimensions != null && data.Length == dimensions.Area * (_outputPixelFormat.BitsPerPixel / 8))
                {
                    BitmapSource output = BitmapSource.Create(dimensions.Width, dimensions.Height, 96, 96, _outputPixelFormat, null, data, dimensions.Width * _outputPixelFormat.BitsPerPixel / 8);
                    output.Freeze();
                    returnValue = ImageCapture.Build(output, highQuality ? CaptureType.PRINT : CaptureType.PREVIEW);
                }
                return(returnValue);
            }
        /// <summary>
        /// https://codelabs.developers.google.com/codelabs/camerax-getting-started#3
        /// </summary>
        private void StartCamera()
        {
            var cameraProviderFuture = ProcessCameraProvider.GetInstance(this);

            cameraProviderFuture.AddListener(new Runnable(() =>
            {
                // Used to bind the lifecycle of cameras to the lifecycle owner
                var cameraProvider = (ProcessCameraProvider)cameraProviderFuture.Get();

                // Preview
                var preview = new Preview.Builder().Build();
                preview.SetSurfaceProvider(viewFinder.CreateSurfaceProvider());

                // Take Photo
                this.imageCapture = new ImageCapture.Builder().Build();

                // Frame by frame analyze
                var imageAnalyzer = new ImageAnalysis.Builder().Build();
                imageAnalyzer.SetAnalyzer(cameraExecutor, new LuminosityAnalyzer(luma =>
                                                                                 Log.Debug(TAG, $"Average luminosity: {luma}")
                                                                                 ));

                // Select back camera as a default, or front camera otherwise
                CameraSelector cameraSelector = null;
                if (cameraProvider.HasCamera(CameraSelector.DefaultBackCamera) == true)
                {
                    cameraSelector = CameraSelector.DefaultBackCamera;
                }
                else if (cameraProvider.HasCamera(CameraSelector.DefaultFrontCamera) == true)
                {
                    cameraSelector = CameraSelector.DefaultFrontCamera;
                }
                else
                {
                    throw new System.Exception("Camera not found");
                }

                try
                {
                    // Unbind use cases before rebinding
                    cameraProvider.UnbindAll();

                    // Bind use cases to camera
                    cameraProvider.BindToLifecycle(this, cameraSelector, preview, imageCapture, imageAnalyzer);
                }
                catch (Exception exc)
                {
                    Log.Debug(TAG, "Use case binding failed", exc);
                    Toast.MakeText(this, $"Use case binding failed: {exc.Message}", ToastLength.Short).Show();
                }
            }), ContextCompat.GetMainExecutor(this)); //GetMainExecutor: returns an Executor that runs on the main thread.
        }
Beispiel #17
0
    public string GetNotes(ImageCapture imgCap)
    {
        string notesTxt = notes + "\n\n";

        if (imagesOfInterest.Contains(imgCap))
        {
            if (imgCap.imageRefRevealed != null)
            {
                return(notesTxt + "Subject:\n" + imgCap.imageRefRevealed.thingRevealed + "\n\nObservation:\n" + imgCap.imageRefRevealed.criticalNote);
            }
        }

        return(notesTxt);
    }
Beispiel #18
0
 private void Awake()
 {
     if (Instance != null)
     {
         Destroy(this);
     }
     else
     {
         Instance = this;
         webTex   = new WebCamTexture();
         //rawImage.texture = webTex;
         //rawImage.material.mainTexture = webTex;
         webTex.Play();
     }
 }
Beispiel #19
0
    public override string GetNotes(int referenceIndexToShow)
    {
        string notesTxt = notes + "\n\n";

        if (referenceIndexToShow < imagesFound.Count)
        {
            ImageCapture img = imagesFound[referenceIndexToShow];

            if (img.imageRefRevealed)
            {
                notesTxt = notesTxt + img.thingRevealed + "  ==>  " + img.imageRefRevealed.criticalNote;
            }
        }

        return(notesTxt);
    }
Beispiel #20
0
    private ImageRefCapture SearchForImageRefInDatabase(ImageCapture imgCap)
    {
        ProjectReview projHandler = FindObjectOfType <ProjectReview>();

        if (projHandler.refImagesOfInterest.Count > 0)
        {
            foreach (ImageRefCapture imgRef in projHandler.refImagesOfInterest)
            {
                if (imgCap.thingRevealed == imgRef.thingRevealed)
                {
                    return(imgRef);
                }
            }
        }

        return(null);
    }
Beispiel #21
0
    public string GetBlurb(ImageCapture imgCap)
    {
        string nameColorHex = ColorUtility.ToHtmlStringRGB(blurbNameColor);
        string occColorHex  = ColorUtility.ToHtmlStringRGB(blurbOccupationColor);
        string descColorHex = ColorUtility.ToHtmlStringRGB(blurbDescriptionColor);

        string blurb = "";

        if (imgCap.imageRefRevealed != null)
        {
            blurb = "<color=#" + nameColorHex + ">" + imgCap.imageRefRevealed.blurbName + "</color>"
                    + "<color=#" + occColorHex + ">" + imgCap.imageRefRevealed.blurbOccupation + "</color>"
                    + "<color=#" + descColorHex + ">" + imgCap.imageRefRevealed.blurbDescription + "</color>";
        }

        return(blurb);
    }
Beispiel #22
0
        static async Task Main(string[] args)
        {
            var cam = new ImageCapture();

            try
            {
                cam.Initialize();
                cam.CaptureImage();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            await AWSUpload.UploadingFileAsync();
        }
Beispiel #23
0
        private async System.Threading.Tasks.Task UpdateImageAsync(ImageCapture param)
        {
            var imageTable = await SqliteHelper.Storage.LoadTableAsync <ImageCapture>();

            var dbIC = imageTable.SingleOrDefault(x => x.CaseServiceRecId == param.CaseServiceRecId && x.FileName == param.FileName);

            if (dbIC == null)
            {
                await SqliteHelper.Storage.InsertSingleRecordAsync <ImageCapture>(param);
            }
            else
            {
                dbIC.ImagePath   = param.ImagePath;
                dbIC.ImageBinary = param.ImageBinary;
                await SqliteHelper.Storage.UpdateSingleRecordAsync <ImageCapture>(dbIC);
            }
        }
        async public virtual System.Threading.Tasks.Task TakePictureAsync(ImageCapture param)
        {
            try
            {
                CameraCaptureUI cam = new CameraCaptureUI();

                var file = await cam.CaptureFileAsync(CameraCaptureUIMode.Photo);

                if (file != null)
                {
                    param.ImagePath = file.Path;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #25
0
        async public virtual System.Threading.Tasks.Task TakePictureAsync(ImageCapture param, string fieldName)
        {
            try
            {
                CameraCaptureUI cam = new CameraCaptureUI();

                var storagefile = await cam.CaptureFileAsync(CameraCaptureUIMode.Photo);

                if (storagefile != null)
                {
                    using (MemoryStream ms = await RenderDataStampOnSnap.RenderStaticTextToBitmap(storagefile))
                    {
                        using (var msrandom = new MemoryRandomAccessStream(ms))
                        {
                            Byte[] bytes = new Byte[ms.Length];
                            await ms.ReadAsync(bytes, 0, (int)ms.Length);

                            // StorageFile file = await KnownFolders.PicturesLibrary.CreateFileAsync("Image.png", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

                            StorageFile file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(DateTime.Now.Ticks.ToString() + storagefile.Name, CreationCollisionOption.ReplaceExisting);

                            using (var strm = await file.OpenStreamForWriteAsync())
                            {
                                await strm.WriteAsync(bytes, 0, bytes.Length);

                                strm.Flush();
                            }

                            param.ImagePath        = file.Path;
                            param.ImageBinary      = Convert.ToBase64String(bytes);
                            param.CaseServiceRecId = ((BaseModel)this.Model).VehicleInsRecID;
                            param.FileName         = fieldName;

                            await UpdateImageAsync(param);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void BindCameraUseCases()
        {
            var metrics = new DisplayMetrics();

            _previewView.Display !.GetRealMetrics(metrics);


            var rotation = GetRotation(_previewView.Display.Rotation);

            var cameraSelector = new CameraSelector.Builder().RequireLensFacing(CameraSelector.LensFacingBack)
                                 .Build();

            var aspectRatio = AspectRatio(metrics.WidthPixels, metrics.HeightPixels);

            _preview = new Preview.Builder()
                       .SetTargetRotation(rotation)
                       .SetTargetAspectRatio(aspectRatio)
                       .Build();

            _imageCapture = new ImageCapture.Builder()
                            .SetCaptureMode(ImageCapture.CaptureModeMinimizeLatency)
                            .SetTargetRotation(rotation)
                            .SetTargetAspectRatio(aspectRatio)
                            .Build();

            var imageAnalyzer = new ImageAnalysis.Builder()
                                .SetTargetRotation(rotation)
                                .SetTargetAspectRatio(aspectRatio)
                                .Build();

            imageAnalyzer.SetAnalyzer(_cameraExecutor, new LuminosityAnalyzer(this));

            _cameraProvider.UnbindAll();
            try
            {
                _camera = _cameraProvider.BindToLifecycle(this, cameraSelector, _preview, _imageCapture, imageAnalyzer);
                _preview.SetSurfaceProvider(_previewView.SurfaceProvider);
            }
            catch (Java.Lang.Exception ex)
            {
                Log.Error(TAG, "Use case binding failed", ex);
            }
        }
        public API_Cropper setup()
        {
            captureComplete     = new AutoResetEvent(false);
            MaxImageCaptureWait = 2000;             // 2 seconds
            var configuration = Configuration.Current;

            CropperImageCapture = new ImageCapture();

            CropperImageCapture.ImageCaptured +=
                (sender, e) => {
                LastImage = new Bitmap(e.FullSizeImage);
                if (onCapture.notNull())
                {
                    onCapture(LastImage);
                }
                captureComplete.Set();
            };
            return(this);
        }
        protected async System.Threading.Tasks.Task TakeSnapshotAsync <T>(T list, string suffix) where T : ObservableCollection <ImageCapture>
        {
            try
            {
                var             props = list.GetType().GetRuntimeProperties();
                CameraCaptureUI ccui  = new CameraCaptureUI()
                {
                };
                ccui.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png;
                var file = await ccui.CaptureFileAsync(CameraCaptureUIMode.Photo);

                if (file != null)
                {
                    using (var stream = await file.OpenReadAsync())
                    {
                        var bytes = new byte[stream.Size];
                        using (var reader = new DataReader(stream))
                        {
                            await reader.LoadAsync((uint)stream.Size);

                            reader.ReadBytes(bytes);
                        }
                        if (file != null)
                        {
                            var ic = new ImageCapture
                            {
                                CaseServiceRecId = this.CaseServiceRecId,
                                PrimeId          = this.Repairid,
                                ImagePath        = file.Path,
                                ImageBinary      = Convert.ToBase64String(bytes),
                                FileName         = string.Format("{0}_{1}_{2}", this.Repairid, suffix, list.Count + 1)
                            };
                            list.Add(ic);
                            await SqliteHelper.Storage.InsertSingleRecordAsync <ImageCapture>(ic);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #29
0
        async public override System.Threading.Tasks.Task TakePictureAsync(ImageCapture param, string fieldName)
        {
            await base.TakePictureAsync(param, fieldName);

            long vehicleInsRecID = long.Parse(ApplicationData.Current.LocalSettings.Values["VehicleInsRecID"].ToString());

            if (vehicleInsRecID != null)
            {
                var viobj = await(this.Model as BaseModel).GetDataAsync(vehicleInsRecID);
                if (viobj != null)
                {
                    var successFlag = await SqliteHelper.Storage.UpdateSingleRecordAsync(this.Model);
                }
                else
                {
                    ((BaseModel)this.Model).VehicleInsRecID = vehicleInsRecID;
                    var successFlag = await SqliteHelper.Storage.InsertSingleRecordAsync(this.Model);
                }
            }
        }
Beispiel #30
0
        public void GenerateIconForLibrary(ModelTransformPair model_transform)
        {
            var zipFileName = model_transform.modelNode.zipFileName;

            if (!string.IsNullOrEmpty(zipFileName))
            {
                if (zipFileName == "313a13a6-9edf-44c7-a81d-50b914e423cc-6bb0e036-df11-4d66-82b3-8b7f0de03d2c")
                {
                    return;
                }

                RecentModelHistory.RecentRecord record = libraryData.GetRecord(zipFileName);
                if (record != null && !string.IsNullOrEmpty(record.iconfilename))
                {
                    ImageGenerated(zipFileName, record.iconfilename);
                    return;
                }
            }
            var iconFileName = GenerateIconFileName(model_transform.modelNode.fileName);

            ImageCapture.GenerateAndSaveIcon(model_transform, iconFileName, new Vector2(400f, 400f), new Color4(0.8431373f, 0.8901961f, 0.9921569f, 1f), glControl, new ImageCapture.PreviewImageCallback(ImageGenerated));
        }