Beispiel #1
0
 public CameraImageSource(Context context)
 {
     this.context  = context;
     cameraControl = new Camera1Control(getContext());
     cameraControl.setCameraFacing(cameraFaceType);
     //cameraControl.setOnFrameListener(new OnFrameListenerAnonymousInnerClass<Camera1Control>());
 }
Beispiel #2
0
        /// <summary>
        /// Creates a new instance of the PelcoD control class
        /// </summary>
        /// <param name="config">configuration for the camera and the method of communication</param>
        /// <param name="cameraControl">parent camera control class that will own this plugin</param>
        public PelcoD(CameraControlInfo config, ICameraControl cameraControl)
        {
            Debug.WriteLine("CameraControls.PelcoD.Load");

            _cameraControl = cameraControl;

            try
            {
                _config = config;
                string portName = ParsePortAndAddress(_config.Address);
                _serialPort = new SerialPort(portName, _baudRate, Parity.None, 8, StopBits.One);
                _serialPort.Open();
                _serialPort.DiscardNull = false;
                _serialPort.DtrEnable   = true;
                _serialPort.ReadTimeout = 10000;

                Debug.WriteLine("CameraControls.PelcoD.Open opened = " + _serialPort.PortName + " @ " + _baudRate + " baud");
            }
            catch (Exception exc)
            {
                ErrorLogger.DumpToDebug(exc);
                throw new Exception("Unable to open serial port", exc);
            }

            _capabilities = _config.Capabilities;
        }
 void Awake()
 {
     _movementControl = this.GetComponent <IMovementController>();
     _weaponSystem    = this.GetComponent <IWeaponSystem>();
     _weaponFire      = this.GetComponent <IWeaponFire>();
     _cameraControl   = this.GetComponent <ICameraControl>();
 }
Beispiel #4
0
 /// <summary>
 /// Creates the correct object based on the config
 /// </summary>
 private void InitInterface()
 {
     this.Cursor = Cursors.AppStarting;
     if (config.Mode == ModeConfig.Modes.Client)
     {
         try
         {
             pluginClient  = null;
             serverClient  = new FutureConcepts.Media.Client.CameraControl(config.ServerAddress);
             currentClient = serverClient;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString(), "Server Client failed.");
         }
     }
     else if (config.Mode == ModeConfig.Modes.Direct)
     {
         try
         {
             serverClient  = null;
             pluginClient  = new DirectCameraControl();
             currentClient = pluginClient;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString(), "Plugin Client failed.");
         }
     }
     this.Cursor = Cursors.Default;
 }
Beispiel #5
0
        /// <summary>
        /// Deletes any/all created interfaces
        /// </summary>
        private void ClearInterface()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                if (serverClient != null)
                {
                    serverClient.Close();
                    serverClient.Opened          -= new EventHandler(cameraControlClient_Opened);
                    serverClient.PropertyChanged -= new PropertyChangedEventHandler(currentClient_PropertyChanged);
                    serverClient.Dispose();
                }
                if (pluginClient != null)
                {
                    pluginClient.Close();
                    pluginClient.PropertyChanged -= new PropertyChangedEventHandler(currentClient_PropertyChanged);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred while disconnecting the current interface. If you encounter further problems, restart this application." +
                                Environment.NewLine + Environment.NewLine + ex.ToString(),
                                "An error occured in ClearInterface()");
            }
            finally
            {
                serverClient  = null;
                pluginClient  = null;
                currentClient = null;
                this.Cursor   = Cursors.Default;
            }
        }
Beispiel #6
0
 /// <summary>
 /// Instantiates a new instance of the plugin
 /// </summary>
 /// <param name="config">configuration information</param>
 /// <param name="cameraControl">owner camera control</param>
 public Visca(CameraControlInfo config, ICameraControl cameraControl)
 {
     CameraControl = cameraControl;
     Debug.WriteLine("CameraControls.Visca");
     _serialPort = new SerialPort(config.Address, 9600, Parity.None, 8, StopBits.One);
     _serialPort.Open();
     _serialPort.DiscardNull = false;
     _serialPort.DtrEnable   = true;
     _serialPort.ReadTimeout = 10000;
     Debug.WriteLine("CameraControls.Visca.Open opened = " + _serialPort.PortName);
     try
     {
         DeviceTypeInquire();
         SetServo(false);
         SetBrake(true);
         SetSlowMode(false);
     }
     catch (Exception exc)
     {
         Debug.WriteLine("Is there a camera attached?");
         _serialPort.Close();
         _serialPort.Dispose();
         _serialPort = null;
         throw exc;
     }
 }
Beispiel #7
0
    //////////////////////////////////////////////////////////////////////////
    // AWAKE
    private void Awake()
    {
        Instance = this;

        MainCamera = transform.GetComponent <Camera>();

        m_CurrentDirection = transform.rotation.eulerAngles;
    }
        private void FindAndOpenCamera()
        {
            bool cameraPermissions = CheckCameraPermissions();

            if (!cameraPermissions)
            {
                return;
            }
            string            errorMessage         = "Unknown error";
            bool              foundCamera          = false;
            IListenableFuture cameraProviderFuture = ProcessCameraProvider.GetInstance(this);

            cameraProviderFuture.AddListener(new Runnable(() =>
            {
                // Camera provider is now guaranteed to be available
                mCameraProvider = cameraProviderFuture.Get() as ProcessCameraProvider;
                try
                {
                    // Find first back-facing camera that has necessary capability.
                    CameraSelector cameraSelector = new CameraSelector.Builder().RequireLensFacing((int)mLensFacing).Build();

                    // Find a good size for output - largest 4:3 aspect ratio that's less than 720p
                    Preview.Builder previewBuilder = new Preview.Builder()
                                                     .SetTargetAspectRatio(AspectRatio.Ratio43);
                    Camera2Interop.Extender previewExtender = new Camera2Interop.Extender(previewBuilder);
                    previewExtender.SetSessionCaptureCallback(mCaptureCallback);
                    Preview preview = previewBuilder.Build();

                    // Must unbind the use-cases before rebinding them
                    mCameraProvider.UnbindAll();
                    ICamera camera = mCameraProvider.BindToLifecycle(
                        this as ILifecycleOwner, cameraSelector, preview);

                    if (camera != null)
                    {
                        // Found suitable camera - get info, open, and set up outputs
                        mCameraInfo    = camera.CameraInfo;
                        mCameraControl = camera.CameraControl;
                        preview.SetSurfaceProvider(this);
                        foundCamera = true;
                    }
                    if (!foundCamera)
                    {
                        errorMessage = GetString(Resource.String.camera_no_good);
                    }

                    SwitchRenderMode(0);
                }
                catch (CameraAccessException e)
                {
                    errorMessage = GetErrorString(e);
                }
                if (!foundCamera)
                {
                    ShowErrorDialog(errorMessage);
                }
            }), ContextCompat.GetMainExecutor(this));
        }
Beispiel #9
0
        /// <summary>
        /// Вращение камеры от горизонтального положения до положения сверху-вниз
        /// </summary>
        /// <param name="Angle">0 - 90</param>
        public void RotateVertical(float Angle)
        {
            if (S is ICameraControl)
            {
                ICameraControl CC = S as ICameraControl;

                CC.RotateVertical(Angle);
            }
        }
Beispiel #10
0
 public CameraViewModel()
 {
     _cameraControl = SelectCameraControl(SelectedLibrary);
     EnableLists    = true;
     GetDevices();
     StartWebCamCommand  = new DelegateCommand(StartWebCam);
     StopWebCamCommand   = new DelegateCommand(StopWebCam);
     TakeSnapshotCommand = new DelegateCommand(TakeSnapshot);
     Events.Clossing    += OnClossing;
 }
Beispiel #11
0
        /// <summary>
        /// Creates an instance of the plugin
        /// </summary>
        /// <param name="config">configuration information</param>
        /// <param name="cameraControl">owning camera control</param>
        public WonwooWCC261(CameraControlInfo config, ICameraControl cameraControl)
            : base(config, cameraControl)
        {
            _serialPort.Handshake = Handshake.None;
            _serialPort.DtrEnable = false;
            _serialPort.RtsEnable = true;

            _stopTimerDelegate = new TimerCallback(SendStopCommand);
            _stopTimer         = new Timer(_stopTimerDelegate, null, Timeout.Infinite, Timeout.Infinite);

            BuildIndexingArray();
        }
Beispiel #12
0
 private void CameraControlFactory_Closed(object sender, EventArgs e)
 {
     _proxy   = null;
     _factory = null;
     if (_keepAliveTimer != null)
     {
         _keepAliveTimer.Enabled = false;
     }
     if (Closed != null)
     {
         Closed(sender, e);
     }
 }
Beispiel #13
0
 /// <summary>
 /// Creates a new instance of the test plugin
 /// </summary>
 /// <param name="config">configuration</param>
 /// <param name="cameraControl">owning parent camera control</param>
 public Test1(CameraControlInfo config, ICameraControl cameraControl)
 {
     try
     {
         _cameraControl = cameraControl;
         Debug.WriteLine("CameraControls.Test1.Load");
         Thread.Sleep(1000); // some fake delay to emulate start/stop of SerialPort
     }
     catch (Exception exc)
     {
         ErrorLogger.DumpToDebug(exc);
     }
 }
Beispiel #14
0
        private void init()
        {
            if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Lollipop)
            {
                cameraControl = new Camera2Control <CameraView>(Context);
            }
            else
            {
                cameraControl = new Camera1Control <CameraView>(Context);
            }
            displayView = cameraControl.getDisplayView();
            AddView(displayView);


            hintView = new ImageView(Context);
            AddView(hintView);
        }
Beispiel #15
0
        /// <summary>
        /// Creates a camera control plugin based on the given <see cref="T:CameraControlInfo"/>
        /// </summary>
        /// <param name="config">Camera control configuration. The type of plugin generated is determined by the <see cref="F:CameraControlInfo.PTZType"/> field.</param>
        /// <param name="cameraControl">owning camera control service</param>
        /// <returns>A plugin for the specified configuration. Note: some configurations could return null.</returns>
        /// <exception cref="T:SourceConfigException">Thrown if an unrecognized or unsupported <see cref="T:PTZType"/> is contained by the configuration.</exception>
        public static ICameraControlPlugin Create(CameraControlInfo config, ICameraControl cameraControl)
        {
            ICameraControlPlugin plugin;

            switch (config.PTZType)
            {
            case PTZType.Visca:
                plugin = new CameraControls.Visca(config, cameraControl);
                break;

            case PTZType.ViscaTest1:
                plugin = new CameraControls.ViscaTest1(config, cameraControl);
                break;

            case PTZType.Null:
                plugin = null;
                Debug.WriteLine("using Null camera control plugin");
                break;

            case PTZType.PelcoD:
                plugin = new CameraControls.PelcoD(config, cameraControl);
                break;

            case PTZType.WWCC:
                plugin = new CameraControls.WonwooWCC261(config, cameraControl);
                break;

            case PTZType.WWCA:
                plugin = new CameraControls.WonwooWCA261(config, cameraControl);
                break;

            case PTZType.Test1:
                plugin = new CameraControls.Test1(config, cameraControl);
                break;

            default:
                throw new SourceConfigException("Unsupported PTZ type (" + config.PTZType.ToString() + ")");
            }
            if (plugin != null)
            {
                Debug.WriteLine("CameraControls.PluginFactory.Create created " + plugin.ToString());
            }
            return(plugin);
        }
        private void tryAddKey(string videoId)
        {
            var            staticInfo = CCTVInfoManager.Instance.GetStaticInfo(videoId);
            ICameraControl cc         = null;

            switch (staticInfo.Platform)
            {
            case  CCTVModels.CCTVPlatformType.CCTV1:
                cc = new CCTV1CameraControl(videoId);
                break;

            case CCTVModels.CCTVPlatformType.CCTV2:
                cc = newCCTV2CameraControl(videoId);
                break;
            }
            if (cc != null)
            {
                _cameraControls.Add(videoId, cc);
            }
        }
Beispiel #17
0
 /// <summary>
 /// Instantiates a new instance of this plugin
 /// </summary>
 /// <param name="config">configuration information</param>
 /// <param name="cameraControl">owning camera control</param>
 public ViscaTest1(CameraControlInfo config, ICameraControl cameraControl)
 {
     CameraControl = cameraControl;
     Debug.WriteLine("CameraControls.ViscaTest1.Initialize");
 }
Beispiel #18
0
 public GetCameraOutputCommand(ICameraControl cameraControl)
 {
     _cameraControl = cameraControl;
 }
 void Awake()
 {
     cameraControl = new PCCameraControl(dragSpeed);
 }
Beispiel #20
0
 /// <summary>
 /// Creates an instance of this plugin
 /// </summary>
 /// <param name="config">configuration information</param>
 /// <param name="cameraControl">owning camera control</param>
 public WonwooWCA261(CameraControlInfo config, ICameraControl cameraControl) : base(config, cameraControl)
 {
 }
Beispiel #21
0
        /// <summary>
        /// 初始化并绑定摄像头
        /// </summary>
        /// <param name="lifecycleOwner"></param>
        public void InitAndStartCamera(ILifecycleOwner lifecycleOwner, Action <bool, string> InitCallBack)
        {
            var cameraProviderFuture = ProcessCameraProvider.GetInstance(this.Context);

            cameraExecutor = Executors.NewSingleThreadExecutor();

            cameraProviderFuture.AddListener(new Java.Lang.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(_CameraPreView.SurfaceProvider);

                // Take Photo
                this._ImageCapture = new ImageCapture.Builder()
                                     .SetTargetResolution(new Size(CaptureImageSize_Width, CaptureImageSize_Height))
                                     .Build();

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

                #region 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");
                switch (CameraFacing)
                {
                case CameraFacing.Back:
                    if (cameraProvider.HasCamera(CameraSelector.DefaultBackCamera) == true)
                    {
                        cameraSelector = CameraSelector.DefaultBackCamera;
                    }
                    else
                    {
                        if (cameraProvider.HasCamera(CameraSelector.DefaultFrontCamera) == true)
                        {
                            cameraSelector = CameraSelector.DefaultFrontCamera;
                        }
                        else
                        {
                            InitCallBack?.Invoke(false, "Not found any camera device");
                            return;
                        }
                    }
                    break;

                case CameraFacing.Front:
                    {
                        if (cameraProvider.HasCamera(CameraSelector.DefaultFrontCamera) == true)
                        {
                            cameraSelector = CameraSelector.DefaultFrontCamera;
                        }
                        else
                        {
                            if (cameraProvider.HasCamera(CameraSelector.DefaultBackCamera) == true)
                            {
                                cameraSelector = CameraSelector.DefaultBackCamera;
                            }
                            else
                            {
                                InitCallBack?.Invoke(false, "Not found any camera device");
                                return;
                            }
                        }
                    }
                    break;
                }
                #endregion
                try
                {
                    // Unbind use cases before rebinding
                    cameraProvider.UnbindAll();
                    // Bind use cases to camera
                    var camera        = cameraProvider.BindToLifecycle(lifecycleOwner, cameraSelector, preview, _ImageCapture, imageAnalyzer);
                    _CameraController = camera.CameraControl;
                    _CameraInfo       = camera.CameraInfo;
                    InitCallBack?.Invoke(true, "");
                }
                catch (Exception exc)
                {
                    Toast.MakeText(this.Context, $"Use case binding failed: {exc.Message}", ToastLength.Short).Show();
                }
            }), AndroidX.Core.Content.ContextCompat.GetMainExecutor(this.Context));
        }
Beispiel #22
0
 public SetCameraResolutionCommand(ICameraControl cameraControl)
 {
     _cameraControl = cameraControl;
 }
Beispiel #23
0
        protected virtual void Awake()
        {
            // Save initial settings in case we wish to restore them
            startSky = RenderSettings.skybox;

            // Pick camera based on platform
            #if WINDOWS_UWP && !UNITY_EDITOR
            cameraCapture = new CameraCaptureUWP();
            #elif (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
            captureCamera = new CameraCaptureARFoundation();
            #else
            // On a desktop computer, or certain laptops, we may not have access to any cameras.
            if (WebCamTexture.devices.Length <= 0)
            {
                // Alternatively, you can simulate a camera by taking screenshots instead.
                // captureCamera = new CameraCaptureScreen(Camera.main);

                // When disabling and returning immediately, OnDisable will be called without
                // OnEnable ever getting called.
                enabled = false;
                return;
            }
            else
            {
                cameraCapture = new CameraCaptureWebcam(Camera.main.transform, Camera.main.fieldOfView);
            }
            #endif

            // Try to get camera control as well
            cameraControl = cameraCapture as ICameraControl;

            // Make sure we have access to a probe in the scene
            if (probe == null)
            {
                probe = FindObjectOfType <ReflectionProbe>();
            }
            if (probe == null)
            {
                GameObject probeObj = new GameObject("_LightCaptureProbe", typeof(ReflectionProbe));
                probeObj.transform.SetParent(transform, false);
                probe = probeObj.GetComponent <ReflectionProbe>();

                probe.size          = Vector3.one * 10000;
                probe.boxProjection = false;
            }

            // Same with a camera object
            if (cameraOrientation == null)
            {
                cameraOrientation = Camera.main.transform;
            }

            // And check for a directional light in the scene
            if (useDirectionalLight && directionalLight == null)
            {
                Light[] lights = FindObjectsOfType <Light>();
                for (int i = 0; i < lights.Length; i++)
                {
                    if (lights[i].type == LightType.Directional)
                    {
                        directionalLight = lights[i];
                        break;
                    }
                }
                if (directionalLight == null)
                {
                    GameObject lightObj = new GameObject("_DirectionalLight", typeof(Light));
                    lightObj.transform.SetParent(transform, false);
                    directionalLight      = lightObj.GetComponent <Light>();
                    directionalLight.type = LightType.Directional;
                }
            }

            // Save initial light settings
            if (directionalLight != null)
            {
                startLightColor      = directionalLight.color;
                startLightRot        = directionalLight.transform.rotation;
                startLightBrightness = directionalLight.intensity;
            }
        }