상속: MonoBehaviour, ITrackerEventHandler
예제 #1
0
        public void testInitialize()
        {
            _goPro   = new GoProDuskWhite();
            _storage = new GenericStorage();

            _service = new TakePicture(_goPro, _storage);
        }
예제 #2
0
        internal void TakePicture()
        {
            if ((m_takePictureAsync == null) && (m_cam != null)) {
                if (m_countdownTimer != null) {
                    m_countdownTimer.Abort();
                    m_countdownTimer = null;
                }

                pictureBox.Text = Language.FormatString(Language.LanguageString.MainForm_TakePicture_TakingPicture);
                m_takePictureAsync = new TakePicture(m_cam.TakePicture);
                m_takePictureAsync.BeginInvoke((AsyncCallback)delegate(IAsyncResult result) {
                    try {
                        pictureBox.DisplayBitmap = m_takePictureAsync.EndInvoke(result);
                        Invoke((MethodInvoker)delegate() {
                            try {
                                Common.SaveJPEG(pictureBox.DisplayBitmap, Path.Combine(Settings.OutputFolder, m_fileName));
                                pictureBox.Text = string.Empty;
                            } catch (Exception) {
                                pictureBox.Text = Language.FormatString(Language.LanguageString.NotifyForm_FailedToSave) + "\r\n" + m_fileName;
                            }
                        });
                    } catch (Exception) {
                        Invoke((MethodInvoker)delegate() {
                            pictureBox.Text = Language.FormatString(Language.LanguageString.NotifyForm_FailedToTakePicture);
                        });
                    } finally {
                        m_takePictureAsync = null;
                        CountdownTimerSetup();
                    }
                }, null);
            }
        }
예제 #3
0
        internal void TakePicture()
        {
            if ((m_takePictureAsync == null) && (m_cam != null))
            {
                if (m_countdownTimer != null)
                {
                    m_countdownTimer.Abort();
                    m_countdownTimer = null;
                }

                pictureBox.Text    = Language.FormatString(Language.LanguageString.MainForm_TakePicture_TakingPicture);
                m_takePictureAsync = new TakePicture(m_cam.TakePicture);
                m_takePictureAsync.BeginInvoke((AsyncCallback) delegate(IAsyncResult result) {
                    try {
                        pictureBox.DisplayBitmap = m_takePictureAsync.EndInvoke(result);
                        Invoke((MethodInvoker) delegate() {
                            try {
                                Common.SaveJPEG(pictureBox.DisplayBitmap, Path.Combine(Settings.OutputFolder, m_fileName));
                                pictureBox.Text = string.Empty;
                            } catch (Exception) {
                                pictureBox.Text = Language.FormatString(Language.LanguageString.NotifyForm_FailedToSave) + "\r\n" + m_fileName;
                            }
                        });
                    } catch (Exception) {
                        Invoke((MethodInvoker) delegate() {
                            pictureBox.Text = Language.FormatString(Language.LanguageString.NotifyForm_FailedToTakePicture);
                        });
                    } finally {
                        m_takePictureAsync = null;
                        CountdownTimerSetup();
                    }
                }, null);
            }
        }
예제 #4
0
        private async void TapGestureRecognizer_Tapped_1(object sender, EventArgs e)
        {
            var actionSheet = await DisplayActionSheet("", "Cancel", null, new string[] { "Take Picture", "Select Picture" });

            if (actionSheet == "Select Picture")
            {
                SelectPicture.Execute(null);
            }
            else if (actionSheet == "Take Picture")
            {
                TakePicture.Execute(null);
            }
        }
예제 #5
0
        private async void ExecuteTakePictureCommand()
        {
            ThereWasADialog = false;
            string path;

            IsUploadImageExecuted = true; try
            {
                path = TakePicture.TakePictureProcess();
                await ProcessImage(path);
            }
            catch (Exception)
            {
                SnackbarMessageQueue.Enqueue("Oops... some error occure, please try again");
            }
            IsUploadImageExecuted = false;
            CommandManager.InvalidateRequerySuggested();
        }
예제 #6
0
    private static int FailCounter     = 0;                     //counts how many times Identify() is called with a bitmap not resembling a digit
    /// <summary>
    /// Compares the cutout at a certain index to all stored digit bitmaps, and returns the best match.
    /// If the digit is different enough from its best match, it is inserted into the digit bitmap array.
    /// </summary>
    /// <param name="bitmap">The bitmap image of the whole sudoku.</param>
    /// <param name="width">The width of the bitmap.</param>
    /// <param name="height">The height of the bitmap.</param>
    /// <param name="index">The index at which the digit was found.</param>
    /// <param name="digits">
    /// A length 10 array of arbitrarily sized arrays of bitmaps, to be used when identifying the digits.
    /// This array can be modified by the function call, inserting and removing new bitmaps.
    /// </param>
    /// <param name="instantMatch">A 0-100 threshold of when two bitmaps should be considered identical.</param>
    /// <param name="maxBitmapsPerDigit">The maximum number of bitmaps each digit should be allowed to store.</param>
    /// <param name="digitout">The extracted digit bitmap, which can be inserted into identifiedBitmaps.</param>
    /// <returns>The digit which was found at the indicated position.</returns>
    public static int Identify(bool[] bitmap, int width, int height, int index, bool[][][,] digits, float instantMatch, int maxBitmapsPerDigit, ref bool[,] digitout)
    {
        #if WRITE_IMAGES_TO_DISK
        TakePicture.colorq.Enqueue(new KeyValuePair <int, Color>(index, Color.blue));
        #endif

        bool[,] digit = ExtractDigit(bitmap, width, height, index); //cut out the digit as a 2d bitmap
        digitout      = digit;

        TakePicture.Visualize(digit);

        //check if every digit is invalid, and if so, alert the user
        if (digit.Length <= 1 || SingleColor(digit))
        {
            if (++FailCounter == 81)
            {
                Popup.queued = new KeyValuePair <string, System.Action>(NoSudokuMessage, null);
                FailCounter  = 0;
            }
            MonoBehaviour.print(FailCounter);
            return(0);
        }

        //identify the digit by checking it against all stored bitmaps
        bool[][,] memoryArray;
        bool[,] digitStretched = new bool[0, 0], memoryStretched = new bool[0, 0];
        float matchpercent, bestPercent = 0;
        int   bestmatch = 0;

        #if CREATE_NEW_DEFAULT
        bestmatch = orderedDigits.Dequeue();
        #else
        for (int i = 1; i <= 9; i++)
        {
            memoryArray = digits[i];
            foreach (var memMap in memoryArray)
            {
                ArrayHandling.StretchToMatch(digit, memMap, out digitStretched, out memoryStretched);
                matchpercent = MatchPercent(digitStretched, memoryStretched);

                if (matchpercent >= instantMatch)
                {
                    return(i);
                }
                if (matchpercent > bestPercent)
                {
                    bestmatch   = i;
                    bestPercent = matchpercent;
                }
            }
        }
        #endif

        //save the bitmap if it is different enough
        bool[][,] bitmaps = digits[bestmatch] ?? new bool[0][, ];
        if (bitmaps.Length < maxBitmapsPerDigit)
        {
            MonoBehaviour.print("Adding digit " + bestmatch + " to storage");
            var temp = new bool[bitmaps.Length + 1][, ];
            for (int i = 0; i < bitmaps.Length; i++)
            {
                temp[i] = bitmaps[i];
            }

            temp[bitmaps.Length] = digit;
            digits[bestmatch]    = temp;
        }
        else
        {
            MonoBehaviour.print("Replacing random stored bitmap for digit " + bestmatch);
            bitmaps[Mathf.FloorToInt((float)random.NextDouble() * bitmaps.Length)] = digit;
        }

        return(bestmatch);
    }
예제 #7
0
        // take picture according to settings right now
        private void TakePicture(object sender, EventArgs e)
        {
            Webcam cam = confWebcam.SelectedItem as Webcam;
            WebcamWithPreview camp = cam as WebcamWithPreview;

            if ((m_takePictureWithPreviewAsync != null) && (sender == takePicturePicture) && (camp != null)) {
                camp.TakePictureEnd();
            }

            if ((m_takePictureAsync == null) && (m_takePictureWithPreviewAsync == null) && (cam != null)) {
                takePictureSaveButton.Enabled = false;
                cam.Config(confResolution.Resolution);

                if (camp != null) {
                    takePicturePicture.Text = string.Empty;
                    BindHelp(takePicturePicture, Language.FormatString(Language.LanguageString.MainForm_Help_VideoStreamFreezeTitle), Language.FormatString(Language.LanguageString.MainForm_Help_VideoStreamFreezeText));

                    camp.DisplacementMap = null;
                    if ((takePictureDisplacement.CurrentPicture != null) && (takePictureDisplacement.CurrentPicture.Picture.Length > 0)) {
                        camp.DisplacementMap = new Bitmap(takePictureDisplacement.CurrentPicture.Picture);
                    }
                    takePicturePicture.DisplayBitmap = new Bitmap(confResolution.Resolution.Size.Width, confResolution.Resolution.Size.Height, confResolution.Resolution.PixelFormat);

                    m_takePictureWithPreviewAsync = new TakePictureWithPreview(camp.TakePicture);
                    m_takePictureWithPreviewAsync.BeginInvoke(takePicturePicture, (AsyncCallback)delegate(IAsyncResult result) {
                        try {
                            m_takePictureWithPreviewAsync.EndInvoke(result);
                            confAcceptButton.Invoke((MethodInvoker)delegate() {
                                takePictureSaveButton.Enabled = true;
                            });
                        } catch (Exception ex) {
                            try {
                                confAcceptButton.Invoke((MethodInvoker)delegate() {
                                    takePicturePicture.Text = Language.FormatString(Language.LanguageString.MainForm_FailedToTakePicture);
                                });
                            } catch (Exception) { }
                        } finally {
                            m_takePictureWithPreviewAsync = null;
                        }
                    }, null);

                } else {
                    BindHelp(takePicturePicture, Language.FormatString(Language.LanguageString.MainForm_Help_PictureTitle), Language.FormatString(Language.LanguageString.MainForm_Help_PictureText));

                    takePicturePicture.Text = Language.FormatString(Language.LanguageString.MainForm_TakePicture_TakingPicture);
                    m_takePictureAsync = new TakePicture(cam.TakePicture);
                    m_takePictureAsync.BeginInvoke((AsyncCallback)delegate(IAsyncResult result) {
                        try {
                            takePicturePicture.DisplayBitmap = m_takePictureAsync.EndInvoke(result);
                            confAcceptButton.Invoke((MethodInvoker)delegate() {
                                takePictureSaveButton.Enabled = true;
                                takePicturePicture.Text = string.Empty;
                            });
                        } catch (Exception ex) {
                            try {
                                confAcceptButton.Invoke((MethodInvoker)delegate() {
                                    takePicturePicture.Text = Language.FormatString(Language.LanguageString.MainForm_FailedToTakePicture);
                                });
                            } catch (Exception) { }
                        } finally {
                            m_takePictureAsync = null;
                        }
                    }, null);
                }
            }
        }
예제 #8
0
 public void RunningProcessTest()
 {
     Assert.IsNotNull(TakePicture.TakePictureProcess());
 }
예제 #9
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title =
                new UILabel(new CGRect(60, 0, NavigationController.Toolbar.Frame.Width,
                                       NavigationController.Toolbar.Frame.Height))
            {
                TextColor       = Style.Header.TextColor,
                BackgroundColor = UIColor.Clear
            };

            GoBackButton = new UIButton(new CGRect(0, 0, 60, NavigationController.Toolbar.Frame.Height))
            {
                TintColor = Style.Header.TextColor,
                Hidden    = true
            };

            GoBackButton.TouchDown += OnClickGoBack;
            GoBackButton.SetImage(UIImage.FromBundle("back").ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), UIControlState.Normal);

            GalleryView = new UIView()
            {
                Hidden = true
            };

            ChoosePicture       = UIButton.FromType(UIButtonType.RoundedRect);
            ChoosePicture.Frame = new CGRect(0, 0, View.Frame.Width / 2, 40);

            ChoosePicture.TintColor       = Style.Header.TextColor;
            ChoosePicture.BackgroundColor = UIColor.LightGray;

            ChoosePicture.SetTitle(Translator.GetText("choose_picture"), UIControlState.Normal);

            ChoosePicture.TouchDown += OnClickChoosePicture;

            TakePicture       = UIButton.FromType(UIButtonType.RoundedRect);
            TakePicture.Frame = new CGRect(View.Frame.Width / 2, 0, View.Frame.Width / 2, 40);

            TakePicture.TintColor       = Style.Header.TextColor;
            TakePicture.BackgroundColor = UIColor.LightGray;

            TakePicture.SetTitle(Translator.GetText("take_picture"), UIControlState.Normal);

            TakePicture.TouchDown += OnClickTakePicture;

            GalleryView.AddSubviews(ChoosePicture, TakePicture);

            NavigationController.NavigationBar.AddSubviews(GoBackButton);

            NavigationController.NavigationBar.TintColor    = Style.Header.TextColor;
            NavigationController.NavigationBar.BarTintColor = Style.Header.BackgroundColor;

            NavigationController.NavigationBar.AddSubviews(Title);

            var scrollView = new UIScrollView(View.Frame)
            {
                ShowsHorizontalScrollIndicator = false,
                AutoresizingMask = UIViewAutoresizing.FlexibleHeight
            };

            WebView = new UIWebView
            {
                ScalesPageToFit = true
            };

            scrollView.AddSubviews(WebView, GalleryView);

            Add(scrollView);

            View.AddConstraints(
                scrollView.AtLeftOf(View),
                scrollView.AtTopOf(View),
                scrollView.WithSameWidth(View),
                scrollView.WithSameHeight(View),

                WebView.AtLeftOf(scrollView),
                WebView.AtTopOf(scrollView),
                WebView.WithSameWidth(scrollView),
                WebView.WithSameHeight(scrollView),

                GalleryView.AtLeftOf(scrollView),
                GalleryView.AtTopOf(scrollView),
                GalleryView.WithSameWidth(scrollView),
                GalleryView.WithSameHeight(scrollView),

                TakePicture.AtLeftOf(GalleryView),
                TakePicture.AtTopOf(GalleryView),

                ChoosePicture.AtRightOf(GalleryView),
                ChoosePicture.AtTopOf(GalleryView)
                );

            View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
            scrollView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

            MenuClickEvent.AddListener(this);

            var menuItem = MenuViewModel.MenuItems.First();

            OnMenuItemClick(menuItem.menu_title, menuItem.url, 0);

            _spinner = new Spinner(View);

            WebView.Delegate = new WebViewDelegate(_spinner, this);
        }
예제 #10
0
    // Update is called once per frame
    void Update()
    {
        if ((SceneAssetCtrl.instance.modelImportAsset != null) && ThreeDModelButton.lastcallGO.Contains(SceneAssetCtrl.instance.modelImportAsset.name))
        { //to watch textures just with OBJ MODELS
            if (GameObject.FindGameObjectsWithTag("texture").Length == 0)
            {
                foreach (Transform go in PanTexMan)
                {  //show texture
                    if (go.gameObject.name.Contains(SceneAssetCtrl.FILEIDENTIFIER))
                    {
                        go.gameObject.SetActive(true);
                    }
                }
                foreach (Transform go in PanTexMan)
                {  //show anim because not OBJ
                    if (go.gameObject.name.Contains(SceneAssetCtrl.ANIMIDENTIFIER))
                    {
                        go.gameObject.SetActive(false);
                    }
                }
            }
        }
        else if (!ThreeDModelButton.lastcallGO.Contains(" "))
        { //because at start lastcallGo=" "
            if (GameObject.FindGameObjectsWithTag("anim").Length == 0)
            {
                foreach (Transform go in PanTexMan)
                {   //remove texture
                    if (go.gameObject.name.Contains(SceneAssetCtrl.FILEIDENTIFIER))
                    {
                        go.gameObject.SetActive(false);
                    }
                }
                foreach (Transform go in PanTexMan)
                {  //show anim because not OBJ
                    if (go.gameObject.name.Contains(SceneAssetCtrl.ANIMIDENTIFIER))
                    {
                        go.gameObject.SetActive(true);
                    }
                }
                if (PanTexMan != null)
                { //else file appear at start
                }
            }
        }
#if UNITY_EDITOR || UNITY_IOS                    //test menu on unity editor
        bool getkey = MenuButton.boolmenubutton; //true menu appear false menu disappears
#elif UNITY_ANDROID
        //#elif UNITY_ANDROID || UNITY_IOS
        //bool getkey =  Input.GetKeyDown (KeyCode.Menu);
        bool getkey = MenuButton.boolmenubutton;
#endif

        //print(menu.GetComponent<RectTransform>().anchoredPosition.y); //test
        //print(menu_button.boolmenubutton+" M51");
        if (getkey)
        {
            RemoveTuto();

            menu.gameObject.transform.localScale = new Vector3(1, 1, 1); //permits continue to use speedz and speedanim values but without use setactive(false)
            menuornot = true;
            MenuButton.boolmenubutton  = false;                          //I TEST
            MenuButton.boolmenubutton2 = false;                          //I TEST
        }
        if (menu.gameObject.transform.localScale.x == 0)
        {
            menuornot = false;
            if (Input.GetKeyDown(KeyCode.Escape))
            { //to take a picture
                Rect   rect     = new Rect(0, 0, Screen.width, Screen.height);
                string fileName = DateTime.Now.Ticks + ".jpg";

                StartCoroutine(TakePicture.TakeScreenshot(rect, fileName, 1)); //without raw image
            }
        }
    }
예제 #11
0
        // take picture according to settings right now
        private void TakePicture(object sender, EventArgs e)
        {
            Webcam            cam  = confWebcam.SelectedItem as Webcam;
            WebcamWithPreview camp = cam as WebcamWithPreview;

            if ((m_takePictureWithPreviewAsync != null) && (sender == takePicturePicture) && (camp != null))
            {
                camp.TakePictureEnd();
            }

            if ((m_takePictureAsync == null) && (m_takePictureWithPreviewAsync == null) && (cam != null))
            {
                takePictureSaveButton.Enabled = false;
                cam.Config(confResolution.Resolution);

                if (camp != null)
                {
                    takePicturePicture.Text = string.Empty;
                    BindHelp(takePicturePicture, Language.FormatString(Language.LanguageString.MainForm_Help_VideoStreamFreezeTitle), Language.FormatString(Language.LanguageString.MainForm_Help_VideoStreamFreezeText));

                    camp.DisplacementMap = null;
                    if ((takePictureDisplacement.CurrentPicture != null) && (takePictureDisplacement.CurrentPicture.Picture.Length > 0))
                    {
                        camp.DisplacementMap = new Bitmap(takePictureDisplacement.CurrentPicture.Picture);
                    }
                    takePicturePicture.DisplayBitmap = new Bitmap(confResolution.Resolution.Size.Width, confResolution.Resolution.Size.Height, confResolution.Resolution.PixelFormat);

                    m_takePictureWithPreviewAsync = new TakePictureWithPreview(camp.TakePicture);
                    m_takePictureWithPreviewAsync.BeginInvoke(takePicturePicture, (AsyncCallback) delegate(IAsyncResult result) {
                        try {
                            m_takePictureWithPreviewAsync.EndInvoke(result);
                            confAcceptButton.Invoke((MethodInvoker) delegate() {
                                takePictureSaveButton.Enabled = true;
                            });
                        } catch (Exception ex) {
                            try {
                                confAcceptButton.Invoke((MethodInvoker) delegate() {
                                    takePicturePicture.Text = Language.FormatString(Language.LanguageString.MainForm_FailedToTakePicture);
                                });
                            } catch (Exception) { }
                        } finally {
                            m_takePictureWithPreviewAsync = null;
                        }
                    }, null);
                }
                else
                {
                    BindHelp(takePicturePicture, Language.FormatString(Language.LanguageString.MainForm_Help_PictureTitle), Language.FormatString(Language.LanguageString.MainForm_Help_PictureText));

                    takePicturePicture.Text = Language.FormatString(Language.LanguageString.MainForm_TakePicture_TakingPicture);
                    m_takePictureAsync      = new TakePicture(cam.TakePicture);
                    m_takePictureAsync.BeginInvoke((AsyncCallback) delegate(IAsyncResult result) {
                        try {
                            takePicturePicture.DisplayBitmap = m_takePictureAsync.EndInvoke(result);
                            confAcceptButton.Invoke((MethodInvoker) delegate() {
                                takePictureSaveButton.Enabled = true;
                                takePicturePicture.Text       = string.Empty;
                            });
                        } catch (Exception ex) {
                            try {
                                confAcceptButton.Invoke((MethodInvoker) delegate() {
                                    takePicturePicture.Text = Language.FormatString(Language.LanguageString.MainForm_FailedToTakePicture);
                                });
                            } catch (Exception) { }
                        } finally {
                            m_takePictureAsync = null;
                        }
                    }, null);
                }
            }
        }
예제 #12
0
    /// <summary>
    /// Initialization code for the major parts of the application.
    /// </summary>
    void Start()
    {
        Screen.fullScreen = false;

        //set up references
        debugText                     = DebugTextInstance.GetComponent <Text>();
        debugText.enabled             = true;
        Instance                      = this;
        Popup.Instance                = infoPopup;
        QuestionPopup.Instance        = questionPopup;
        BitmapEncoding.PersistentPath = Application.persistentDataPath;

        foreach (var v in WebCamTexture.devices)
        {
            print("\"" + v.name + "\"" + (v.isFrontFacing ? " (Front facing)" : ""));
        }
        print("Persistent: " + BitmapEncoding.PersistentPath);

        //load persistent data
        Status        = "Loading Digit Bitmaps";
        storedBitmaps = BitmapEncoding.LoadBitmaps();
        Status        = "Loading Settings";
        SettingManager.LoadSettings();

        //start camera
        Status = "Looking for cameras";
        try
        {
            texture = new WebCamTexture(CameraName);
            texture.Play();
            if (WebCamTexture.devices.Length == 0)
            {
                throw new System.Exception(NoCamerasMessage);
            }
        }
        catch (System.Exception e)
        {
            Popup.ActivatePopup("Could not start the camera:" + System.Environment.NewLine + e.Message);
            CameraUI.enabled = OverlayUI.enabled = false;
        }
        textureWidth  = texture.width;
        textureHeight = texture.height;
        side          = Mathf.Min(textureWidth, textureHeight) - 10;

        //create overlay, rotate and stretch images correctly
        Status = "Assigning images";
        Texture2D overlay = CreateOverlay(textureWidth, textureHeight, side);

        OverlayUI.texture = overlay;
        CameraUI.texture  = texture;
        CameraUI.GetComponent <AspectRatioFitter>().aspectRatio = textureWidth / (float)textureHeight;
        if ((texture.videoRotationAngle + 360) % 180 == 90)
        {
            int i = textureWidth;
            textureWidth  = textureHeight;
            textureHeight = i;
        }
        CameraUI.transform.parent.localEulerAngles = new Vector3(0, 0, -texture.videoRotationAngle);

        SudokuPanel.GetComponent <SudokuCreator>().Init();

        Status            = "Ready to take picture";
        debugText.enabled = false;
    }