private void ShowResults(IInputOutputArray image,
                                 List <IInputOutputArray> licensePlateImagesList,
                                 List <IInputOutputArray> filteredLicensePlateImagesList,
                                 List <RotatedRect> licenseBoxList,
                                 List <string> words)
        {
            var refinnedWords = new List <string>();


            Android.Graphics.Point startPoint = new Android.Graphics.Point(10, 10);

            if (words.Any() && words.Count != 0)
            {
                for (int i = 0; i < licensePlateImagesList.Count; i++)
                {
                    if (licensePlateImagesList.Count > 0)
                    {
                        string replacement2 = Regex.Replace(words[i], @"\t|\n|\r", "");
                        string replacement  = Regex.Replace(replacement2, "[^0-9a-zA-Z]+", "");

                        Rectangle rect = licenseBoxList[i].MinAreaRect();
                        CvInvoke.Rectangle(image, rect, new Bgr(System.Drawing.Color.Red).MCvScalar, 2);
                        refinnedWords.Add(replacement);
                    }
                }
            }
            else
            {
                refinnedWords.Add("Not licence was found");
            }
            ShowLicencePlateOnScreen(refinnedWords);
        }
Beispiel #2
0
        private void SetZoomScaleAndMenuButtonScale()
        {
            Android.Graphics.Point point = new Android.Graphics.Point();
            this.WindowManager.DefaultDisplay.GetRealSize(point);
            float num  = point.X;
            float num2 = point.Y;
            float num3 = System.Math.Min(this.Resources.DisplayMetrics.Xdpi, this.Resources.DisplayMetrics.Ydpi);

            if (point.Y > point.X)
            {
                num  = point.Y;
                num2 = point.X;
            }
            ScreenWidthPixels  = (int)num;
            ScreenHeightPixels = (int)num2;
            float num4 = num3 * 0.3f;
            float num5 = num2 / num4;
            float val  = num4 / 64f;

            if (num5 < 10f)
            {
                num4 = num3 * 0.225f;
                val  = num4 / 64f;
            }
            ZoomScale       = System.Math.Max(0.5f, System.Math.Min(val, 5f));
            MenuButtonScale = num3 * 0.2f / 64f;
            MenuButtonScale = System.Math.Max(0.5f, System.Math.Min(MenuButtonScale, 5f));
            Console.WriteLine("MainActivity.SetZoomScale width:" + num + ", height:" + num2 + ", dpi:" + num3 + ", pixelsPerTile:" + num4 + ", ZoomScale:" + ZoomScale + ", MenuButtonScale:" + MenuButtonScale);
        }
Beispiel #3
0
        public AndroidAgent(
            IActivityTracker activityTracker,
            int contentId = -1)
        {
            this.contentId = contentId;

            var windowManager = Application.Context.GetSystemService(
                global::Android.Content.Context.WindowService)
                                .JavaCast <IWindowManager> ();

            displaySize = GetRealSize(windowManager.DefaultDisplay);

            ActivityTracker = activityTracker;

            Identity = new AgentIdentity(
                AgentType.Android,
                new Sdk(
                    new FrameworkName(typeof(Java.Interop.Runtime)
                                      .Assembly
                                      .GetCustomAttribute <TargetFrameworkAttribute> ()
                                      .FrameworkName),
                    Array.Empty <string> (),
                    "Android"),
                GetApplicationName(),
                deviceManufacturer: Build.Manufacturer,
                screenWidth: displaySize.X,
                screenHeight: displaySize.Y);

            RepresentationManager.AddProvider(new AndroidRepresentationProvider());

            ViewHierarchyHandlerManager.AddViewHierarchyHandler("Android", this);
        }
Beispiel #4
0
        void ISurfaceHolderCallback.SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height)
        {
            var surfaceRect = holder.SurfaceFrame;

            Size = new System.Drawing.Size(surfaceRect.Right - surfaceRect.Left, surfaceRect.Bottom - surfaceRect.Top);
            // We don't use Display's rotation to determine orientation because it shows rotation
            // from "natural" orientation. On some devices 0 degrees may refer to portrait and on some devices
            // 0 degrees may refer to landscape.
            DeviceOrientation orientation;

            using (var realSize = new Android.Graphics.Point()) {
                // On some tablets Surface may be created twice after resuming game if orientation is restricted -
                // For example if you use tablet in landscape and game is restricted to portrait,
                // surface will be created for landscape and on a next frame recreated for portrait.
                // So we prefer to use Display's Real Size which seems always follow restricted orientation.
                windowManager.DefaultDisplay.GetRealSize(realSize);
                orientation = realSize.X < realSize.Y ? DeviceOrientation.Portrait : DeviceOrientation.LandscapeLeft;
            }
            var deviceRotated = Application.CurrentDeviceOrientation != orientation;

            Application.CurrentDeviceOrientation = orientation;
            Resize?.Invoke(this, new ResizeEventArgs {
                DeviceRotated = deviceRotated
            });
        }
        /// <summary>
        /// 计算图片上下边线焦点
        /// </summary>
        /// <param name="points"></param>
        private void CalStraightLine(List <Point> points)
        {
            SpecifiedPointS = new List <Point>();
            float[] mX = new float[points.Count];
            float[] mY = new float[points.Count];
            for (int i = 0; i < points.Count; i++)
            {
                mX[i] = points[i].X;
                mY[i] = points[i].Y;
            }

            float k = 0;
            float b = 0;

            //LeastSquareMethod(mX, mY,ref k, ref b);
            Point Ps = points[5];
            Point Pe = points[points.Count - 2];

            k = Convert.ToSingle(Ps.Y - Pe.Y) / (Ps.X - Pe.X);
            if (Single.IsInfinity(k))
            {
                Point p1 = new Point(Ps.X, 0);
                //和下面焦点(y=图片的高)
                int y = Imageheight;

                Point p2 = new Point(Ps.X, y);
                newLinePoints.Add(p1);
                newLinePoints.Add(p2);
            }
            else
            {
                b = Pe.Y - k * Pe.X;
                //和上面(x=0)焦点
                int   x  = Convert.ToInt32(-b / k);
                Point p1 = new Point(x, 0);
                //和下面焦点(y=图片的高)
                int y = Imageheight;
                x = Convert.ToInt32((y - b) / k);
                Point p2 = new Point(x, y);
                newLinePoints.Add(p1);
                newLinePoints.Add(p2);
            }

            for (int i = 0; i < Imageheight; i++)
            {
                if (Single.IsInfinity(k))
                {
                    Point p = new Point(Ps.X, i);
                    SpecifiedPointS.Add(p);
                }
                else
                {
                    int   x = Convert.ToInt32((i - b) / k);
                    Point p = new Point(x, i);
                    SpecifiedPointS.Add(p);
                }
            }
        }
        public ImageListItemAdapter(Context context, IList <string> items) : base(context, items)
        {
            var wm = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            var sz = new Android.Graphics.Point();

            wm.DefaultDisplay.GetSize(sz);
            Width = (int)(sz.X * 0.9);
            CulculateTotalHeight();
        }
 public DragObject(Resources res, int drawable, Point point)
 {
     BitmapFactory.Options options = new BitmapFactory.Options();
     options.InJustDecodeBounds = true;
     img = BitmapFactory.DecodeResource(res, drawable);
     id = count;
     count++;
     coordX = point.X;
     coordY = point.Y;
 }
Beispiel #8
0
        public PointF TransformPoint(Point p)
        {
            var px = new ag.Point[] { Conversions.ToAndroidPoint(p) };

#if TODO
            this.Control.TransformPoints(px);

            return(Platform.Conversions.ToEto(px[0]));
#else
            throw new NotImplementedException();
#endif
        }
Beispiel #9
0
        public static Point GetScreenResolution(Context context)
        {
            DisplayMetrics displayMetrics = new DisplayMetrics();

            IWindowManager windowManager = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager> ();

            windowManager.DefaultDisplay.GetMetrics(displayMetrics);

            Point screenResolution = new Point(displayMetrics.WidthPixels, displayMetrics.HeightPixels);

            return(screenResolution);
        }
        /// <summary>
        /// Equivalent of Display.GetRealSize (introduced in API 17), except this version works as far back as
        /// API 14.
        /// </summary>
        static AG.Point GetRealSize(Display display)
        {
            var realSize = new AG.Point();

            var klassDisplay  = JNIEnv.FindClass("android/view/Display");
            var displayHandle = JNIEnv.ToJniHandle(display);

            try {
                // If the OS is running Jelly Bean (API 17), we can call Display.GetRealSize via JNI
                if ((int)Build.VERSION.SdkInt >= 17 /*BuildVersionCodes.JellyBeanMr1*/)
                {
                    var getRealSizeMethodId = JNIEnv.GetMethodID(
                        klassDisplay,
                        "getRealSize",
                        "(Landroid/graphics/Point;)V");

                    JNIEnv.CallVoidMethod(
                        displayHandle, getRealSizeMethodId, new JValue(realSize));
                }
                else if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich)
                {
                    // Otherwise, this OS is older. As long as it's API 14-16, these private
                    // methods can get the real size.
                    var rawHeightMethodId = JNIEnv.GetMethodID(
                        klassDisplay,
                        "getRawHeight",
                        "()I");
                    var rawWidthMethodId = JNIEnv.GetMethodID(
                        klassDisplay,
                        "getRawWidth",
                        "()I");

                    var height = JNIEnv.CallIntMethod(displayHandle, rawHeightMethodId);
                    var width  = JNIEnv.CallIntMethod(displayHandle, rawWidthMethodId);

                    realSize = new AG.Point(width, height);
                }
                else
                {
                    // Just return something for API < 14
                    display.GetSize(realSize);
                }
            } finally {
                JNIEnv.DeleteGlobalRef(klassDisplay);
            }

            return(realSize);
        }
Beispiel #11
0
        internal static ag.Point[] ToAndroid(this Point[] points)
        {
            var result =
                new ag.Point[points.Length];

            for (var i = 0;
                 i < points.Length;
                 ++i)
            {
                var p = points[i];
                result[i] =
                    new ag.Point(p.X, p.Y);
            }

            return(result);
        }
Beispiel #12
0
        public ShowcaseStep()
        {
            DismissText = null;
            DismissTextColor = DefaultTextColor;
            DismissOnTouch = false;

            ContentText = null;
            ContentTextColor = DefaultTextColor;

            Position = new Point(int.MaxValue, int.MaxValue);
            Radius = DefaultRadius;
            MaskColor = DefaultMaskColor;

            Delay = DefaultDelay;
            FadeInDuration = DefaultFadeTime;
            FadeOutDuration = DefaultFadeTime;
        }
Beispiel #13
0
        public void OnMapLoaded()
        {
            // Map.Projection = new ProjectionImpl(mapView);
            mapView.OnResume();
            Map.SendLoaded();

            //指南针位置
            mapView.Map.SetCompassEnable(false);
            //mapView.Map.CompassPosition = new AG.Point(50, 50);
            ///

            //百度地图API SDK 3.0.0版本以上该方法设置比例尺/缩放控件的位置
            AG.Point point = new AG.Point();
            point.X = 20;
            point.Y = 20;
            mapView.SetZoomControlsPosition(point);
        }
Beispiel #14
0
        /// <summary>
        /// プレビューの画面サイズを算出
        /// </summary>
        /// <param name="cameraId"></param>
        /// <returns></returns>
        private Android.Util.Size GetPreviewSize(string cameraId)
        {
            CameraManager          manager         = (CameraManager)activity.GetSystemService(Context.CameraService);
            var                    characteristics = manager.GetCameraCharacteristics(cameraId);
            StreamConfigurationMap map             = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
            // 最大サイズからratioを取得
            var maxSize = (Android.Util.Size)Collections.Max(Arrays.AsList(map.GetOutputSizes((int)ImageFormatType.Jpeg)), new CompareSizesByArea());
            int h       = maxSize.Height;
            int w       = maxSize.Width;

            System.Diagnostics.Debug.WriteLine($"max size: width={w},height={h}");

            // ディスプレイサイズ
            var displaySize = new Android.Graphics.Point();

            activity.WindowManager.DefaultDisplay.GetSize(displaySize);
            // 横向きに補正
            var maxWidth  = displaySize.X > displaySize.Y ? displaySize.X : displaySize.Y;
            var maxHeight = displaySize.Y < displaySize.X ? displaySize.Y : displaySize.X;

            System.Diagnostics.Debug.WriteLine($"display: width={maxWidth},height={maxHeight}");

            // 画面サイズに収まり、アスペクト比が一致するサイズ
            var list  = new List <Android.Util.Size>();
            var sizes = map.GetOutputSizes(Class.FromType(typeof(SurfaceTexture)));

            foreach (var size in sizes)
            {
                System.Diagnostics.Debug.WriteLine($"size: width={size.Width},height={size.Height}");

                if ((size.Width <= maxWidth) && (size.Height <= maxHeight) && size.Height == size.Width * h / w)
                {
                    list.Add(size);
                }
            }

            // 最大のやつを取得
            var prevSize = (Android.Util.Size)Collections.Max(list, new CompareSizesByArea());
            // 無理から縦向きに変更
            var ret = new Android.Util.Size(prevSize.Height, prevSize.Width);

            return(ret);
        }
Beispiel #15
0
        public static Point GetShowcasePointFromView(View view, ShowcaseView.ConfigOptions options)
        {
            var result = new Point();

            if (options.Insert == ShowcaseView.INSERTTOVIEW)
            {
                result.X = view.Left + view.Width / 2;
                result.Y = view.Top + view.Height / 2;
            }
            else
            {
                var coordinates = new int[2];

                view.GetLocationInWindow(coordinates);
                result.X = coordinates[0] + view.Width / 2;
                result.Y = coordinates[1] + view.Height / 2;
            }
            return result;
        }
Beispiel #16
0
        protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
        {
            base.OnSizeChanged(w, h, oldw, oldh);

            this.Measure((int)MeasureSpecMode.Unspecified, (int)MeasureSpecMode.Unspecified);
            CURVE_CIRCLE_RADIUS = this.MeasuredHeight / 2;

            mNavigationBarWidth  = Width;
            mNavigationBarHeight = Height;
            // the coordinates (x,y) of the start point before curve
            mFirstCurveStartPoint.Set((mNavigationBarWidth / 2) - (CURVE_CIRCLE_RADIUS * 2) - (CURVE_CIRCLE_RADIUS / 3), 0);
            // the coordinates (x,y) of the end point after curve
            mFirstCurveEndPoint.Set(mNavigationBarWidth / 2, CURVE_CIRCLE_RADIUS + (CURVE_CIRCLE_RADIUS / 4));
            // same thing for the second curve
            mSecondCurveStartPoint = mFirstCurveEndPoint;
            mSecondCurveEndPoint.Set((mNavigationBarWidth / 2) + (CURVE_CIRCLE_RADIUS * 2) + (CURVE_CIRCLE_RADIUS / 3), 0);

            // the coordinates (x,y)  of the 1st control point on a cubic curve
            mFirstCurveControlPoint1.Set(mFirstCurveStartPoint.X + CURVE_CIRCLE_RADIUS + (CURVE_CIRCLE_RADIUS / 4), mFirstCurveStartPoint.Y);
            // the coordinates (x,y)  of the 2nd control point on a cubic curve
            mFirstCurveControlPoint2.Set(mFirstCurveEndPoint.X - (CURVE_CIRCLE_RADIUS * 2) + CURVE_CIRCLE_RADIUS, mFirstCurveEndPoint.Y);

            mSecondCurveControlPoint1.Set(mSecondCurveStartPoint.X + (CURVE_CIRCLE_RADIUS * 2) - CURVE_CIRCLE_RADIUS, mSecondCurveStartPoint.Y);
            mSecondCurveControlPoint2.Set(mSecondCurveEndPoint.X - (CURVE_CIRCLE_RADIUS + (CURVE_CIRCLE_RADIUS / 4)), mSecondCurveEndPoint.Y);

            mPath.Reset();
            mPath.MoveTo(0, 0);
            mPath.LineTo(mFirstCurveStartPoint.X, mFirstCurveStartPoint.Y);

            mPath.CubicTo(mFirstCurveControlPoint1.X, mFirstCurveControlPoint1.Y,
                          mFirstCurveControlPoint2.X, mFirstCurveControlPoint2.Y,
                          mFirstCurveEndPoint.X, mFirstCurveEndPoint.Y);

            mPath.CubicTo(mSecondCurveControlPoint1.X, mSecondCurveControlPoint1.Y,
                          mSecondCurveControlPoint2.X, mSecondCurveControlPoint2.Y,
                          mSecondCurveEndPoint.X, mSecondCurveEndPoint.Y);

            mPath.LineTo(mNavigationBarWidth, 0);
            mPath.LineTo(mNavigationBarWidth, mNavigationBarHeight);
            mPath.LineTo(0, mNavigationBarHeight);
            mPath.Close();
        }
        protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
        {
            base.OnSizeChanged(w, h, oldw, oldh);

            // get width and height of navigation bar
            // Navigation bar bounds (width & height)
            mNavigationBarWidth  = Width;
            mNavigationBarHeight = Height;
            differenceOfScreen   = Height - tabHeight;

            // the coordinates (x,y) of the start point before curve
            //mFirstCurveStartPoint.Set((mNavigationBarWidth / 2) - (CURVE_CIRCLE_RADIUS * 2) - (CURVE_CIRCLE_RADIUS / 3), differenceOfScreen);
            //// the coordinates (x,y) of the end point after curve
            //mFirstCurveEndPoint.Set(mNavigationBarWidth / 2, CURVE_CIRCLE_RADIUS + (CURVE_CIRCLE_RADIUS / 4) + differenceOfScreen);
            //// same thing for the second curve
            //mSecondCurveStartPoint = mFirstCurveEndPoint;
            //mSecondCurveEndPoint.Set((mNavigationBarWidth / 2) + (CURVE_CIRCLE_RADIUS * 2) + (CURVE_CIRCLE_RADIUS / 3), differenceOfScreen);

            //// the coordinates (x,y)  of the 1st control point on a cubic curve
            //mFirstCurveControlPoint1.Set(mFirstCurveStartPoint.X + CURVE_CIRCLE_RADIUS + (CURVE_CIRCLE_RADIUS / 4), mFirstCurveStartPoint.Y);
            //// the coordinates (x,y)  of the 2nd control point on a cubic curve
            //mFirstCurveControlPoint2.Set(mFirstCurveEndPoint.X - (CURVE_CIRCLE_RADIUS * 2) + CURVE_CIRCLE_RADIUS, mFirstCurveEndPoint.Y);

            //mSecondCurveControlPoint1.Set(mSecondCurveStartPoint.X + (CURVE_CIRCLE_RADIUS * 2) - CURVE_CIRCLE_RADIUS, mSecondCurveStartPoint.Y);
            //mSecondCurveControlPoint2.Set(mSecondCurveEndPoint.X - (CURVE_CIRCLE_RADIUS + (CURVE_CIRCLE_RADIUS / 4)), mSecondCurveEndPoint.Y);

            var x1 = (mNavigationBarWidth - CURVE_CIRCLE_RADIUS * 2) / 2;
            var r  = CURVE_CIRCLE_RADIUS / 2;
            var R  = CURVE_CIRCLE_RADIUS;

            mFirstCurveStartPoint.Set(x1 - r / 3, differenceOfScreen);
            mFirstCurveEndPoint.Set(x1 + r, differenceOfScreen + r + r / 3);

            mSecondCurveStartPoint = mFirstCurveEndPoint;
            mSecondCurveEndPoint.Set(x1 + R + 2 * r / 3, differenceOfScreen);

            mFirstCurveControlPoint1.Set(x1 + r, differenceOfScreen);
            mFirstCurveControlPoint2.Set(x1 + r, differenceOfScreen + r + r / 3);

            mSecondCurveControlPoint1.Set(x1 + r + r / 2, differenceOfScreen + r + r / 3);
            mSecondCurveControlPoint2.Set(x1 + r + r / 2, differenceOfScreen);
        }
Beispiel #18
0
        // Defines a callback that sends the drag shadow dimensions and touch point back to the system.
        public override void OnProvideShadowMetrics(Android.Graphics.Point outShadowSize, Android.Graphics.Point outShadowTouchPoint)
        {
            double rotationRad = Java.Lang.Math.ToRadians(View.Rotation);
            int    w           = (int)(View.Width * View.ScaleX);
            int    h           = (int)(View.Height * View.ScaleY);
            double s           = Java.Lang.Math.Abs(Java.Lang.Math.Sin(rotationRad));
            double c           = Java.Lang.Math.Abs(Java.Lang.Math.Cos(rotationRad));


            //calculate the size of the canvas
            //width = view's width*cos(rad)+height*sin(rad)
            width = (int)(w * c + h * s);
            //height = view's width*sin(rad)+height*cos(rad)
            height = (int)(w * s + h * c);

            outShadowSize.Set(width, height);

            // Sets the touch point's position to be in the middle of the drag shadow
            outShadowTouchPoint.Set(outShadowSize.X / 2, outShadowSize.Y / 2);
        }
Beispiel #19
0
        public static Point GetSize(Display display)
        {
            int width;
            int heigth;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.HoneycombMr2)
            {
                Point size = new Point();
                display.GetSize(size);

                width = size.X;
                heigth = size.Y;
            }
            else
            {
                 width = display.Width;
                 heigth = display.Height;
            }
            return new Point(width, heigth);
        }
Beispiel #20
0
        public static Rect CreateRectFromBoundingBox1(BoundingBox bbox, MapView mapView)
        {
            var projection = mapView.Projection;

            Point ul = projection.ToPixels(new GeoPoint(bbox.Ul.LatitudeE6, bbox.Ul.LongitudeE6), null);

            Point ur = projection.ToPixels(new GeoPoint(bbox.Ul.LatitudeE6, bbox.Lr.LongitudeE6), null);

            Point ll = projection.ToPixels(new GeoPoint(bbox.Lr.LatitudeE6, bbox.Ul.LongitudeE6), null);

            Point lr = projection.ToPixels(new GeoPoint(bbox.Lr.LatitudeE6, bbox.Lr.LongitudeE6), null);

            Point[] points = new Point[4];
            points[0] = ul;
            points[1] = ur;
            points[2] = ll;
            points[3] = lr;
            int l = 0; int r = 0; int t = 0; int b = 0;
            for (int i = 0; i < points.Length; i++)
            {
                if ((points[i].X < l) || (l == 0))
                {
                    l = points[i].X;
                }
                if ((points[i].X > r) || (r == 0))
                {
                    r = points[i].X;
                }
                if ((points[i].Y < t) || (t == 0))
                {
                    t = points[i].Y;
                }
                if ((points[i].Y > b) || (b == 0))
                {
                    b = points[i].Y;
                }
            }
            Rect image_region = new Rect(l, t, r, b);

            return image_region;
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Java.Lang.Thread.DefaultUncaughtExceptionHandler = new UnhandledExceptionHandler(this);

            Window.AddFlags(WindowManagerFlags.Fullscreen);
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            Point displaySize = new Point();
            WindowManager.DefaultDisplay.GetSize(displaySize);
            vsv = new VideoStreamsView(this, displaySize);
            SetContentView(vsv);

            abortUnless(PeerConnectionFactory.InitializeAndroidGlobals(this), "Failed to initializeAndroidGlobals");

            AudioManager audioManager = ((AudioManager)GetSystemService(AudioService));
            // TODO(fischman): figure out how to do this Right(tm) and remove the
            // suppression.
            bool isWiredHeadsetOn = audioManager.WiredHeadsetOn;
            audioManager.Mode = isWiredHeadsetOn ? Mode.InCall : Mode.InCommunication;
            audioManager.SpeakerphoneOn = !isWiredHeadsetOn;

            sdpMediaConstraints = new MediaConstraints();
            sdpMediaConstraints.Mandatory.Add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
            sdpMediaConstraints.Mandatory.Add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));

            Intent intent = Intent;
            if ("Android.intent.action.VIEW".Equals(intent.Action))
            {
                connectToRoom(intent.Data.ToString());
                return;
            }
            showGetRoomUI();
        }
        // Sets up member variables related to camera.
        private void SetUpCameraOutputs(int width, int height)
        {
            var activity = Activity;
            var manager  = (CameraManager)activity.GetSystemService(Context.CameraService);

            try
            {
                for (var i = 0; i < manager.GetCameraIdList().Length; i++)
                {
                    var cameraId = manager.GetCameraIdList()[i];
                    CameraCharacteristics characteristics = manager.GetCameraCharacteristics(cameraId);

                    // We don't use a front facing camera in this sample.
                    var facing = (Integer)characteristics.Get(CameraCharacteristics.LensFacing);
                    if (facing != null && facing == Integer.ValueOf((int)LensFacing.Front))
                    {
                        continue;
                    }

                    var map = (StreamConfigurationMap)characteristics.Get(
                        CameraCharacteristics.ScalerStreamConfigurationMap);
                    if (map == null)
                    {
                        continue;
                    }

                    // For still image captures, we use the largest available size.
                    Size largest = (Size)Collections.Max(
                        Arrays.AsList(map.GetOutputSizes((int)ImageFormatType.Jpeg)),
                        new CompareSizesByArea());

                    ConfigureImageReader(largest);

                    bool swappedDimensions = GetDimmensions(activity, characteristics);

                    Point displaySize = new Point();
                    activity.WindowManager.DefaultDisplay.GetSize(displaySize);
                    var rotatedPreviewWidth  = width;
                    var rotatedPreviewHeight = height;
                    var maxPreviewWidth      = displaySize.X;
                    var maxPreviewHeight     = displaySize.Y;

                    if (swappedDimensions)
                    {
                        rotatedPreviewWidth  = height;
                        rotatedPreviewHeight = width;
                        maxPreviewWidth      = displaySize.Y;
                        maxPreviewHeight     = displaySize.X;
                    }

                    if (maxPreviewWidth > MAX_PREVIEW_WIDTH)
                    {
                        maxPreviewWidth = MAX_PREVIEW_WIDTH;
                    }

                    if (maxPreviewHeight > MAX_PREVIEW_HEIGHT)
                    {
                        maxPreviewHeight = MAX_PREVIEW_HEIGHT;
                    }

                    // Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
                    // bus' bandwidth limitation, resulting in gorgeous previews but the storage of
                    // garbage capture data.
                    mPreviewSize = ChooseOptimalSize(
                        map.GetOutputSizes(Class.FromType(typeof(SurfaceTexture))),
                        rotatedPreviewWidth,
                        rotatedPreviewHeight,
                        maxPreviewWidth,
                        maxPreviewHeight,
                        largest);

                    DisplayMetrics displayMetrics = new DisplayMetrics();
                    activity.WindowManager.DefaultDisplay.GetMetrics(displayMetrics);
                    var dsiWidth = displayMetrics.WidthPixels;

                    var resolutionWidth  = mPreviewSize.Height;
                    var resolutionHeigth = mPreviewSize.Width;

                    int newHeight = 0;
                    if (resolutionWidth > resolutionHeigth)
                    {
                        newHeight = dsiWidth * resolutionWidth / resolutionHeigth;
                    }
                    else
                    {
                        newHeight = dsiWidth * resolutionHeigth / resolutionWidth;
                    }

                    int newWidth = dsiWidth;
                    mTextureView.LayoutParameters = new FrameLayout.LayoutParams(newWidth, newHeight);

                    // Check if the flash is supported.
                    var available = (Boolean)characteristics.Get(CameraCharacteristics.FlashInfoAvailable);
                    if (available == null)
                    {
                        mFlashSupported = false;
                    }
                    else
                    {
                        mFlashSupported = (bool)available;
                    }

                    mCameraId = cameraId;
                    return;
                }
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
            catch (NullPointerException)
            {
                // Currently an NPE is thrown when the Camera2API is used but not supported on the
                // device this code runs.
                // ErrorDialog.NewInstance(GetString(Resource.String.camera_error)).
                // Show(ChildFragmentManager, FRAGMENT_DIALOG);
            }
        }
        public void setBehindWidth(int i)
        {
            int width = 0;
            Display display = ((IWindowManager)Context.GetSystemService(Context.WindowService))
                    .DefaultDisplay;


            try
            {
                //Class<?> cls = Display.class;
                //Class<?>[] parameterTypes = {Point.class};
                //Point parameter = new Point();
                //Method method = cls.getMethod("getSize", parameterTypes);
                //method.invoke(display, parameter);
                //width = parameter.x;
                Point parameter = new Point();
                display.GetSize(parameter);
                width = parameter.X;
            }
            catch (Exception e)
            {
                //width = display.getWidth();
            }
            setBehindOffset(width - i);
        }
Beispiel #24
0
		internal static ag.Point[] ToAndroid(this Point[] points)
		{
			var result =
				new ag.Point[points.Length];

			for (var i = 0;
				i < points.Length;
				++i)
			{
				var p = points[i];
				result[i] =
					new ag.Point(p.X, p.Y);
			}

			return result;
		}
Beispiel #25
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AppPreference appPreference = new AppPreference();

            CvInvoke.UseOpenCL = false;  //appPreference.UseOpenCL;
            string oclDeviceName = appPreference.OpenClDeviceName;

            if (!string.IsNullOrEmpty(oclDeviceName))
            {
                CvInvoke.OclSetDefaultDevice(oclDeviceName);
                Log.Error(TAG, "\t\t --OclSetDefaultDevice: " + oclDeviceName);
            }

            mFile = new Java.IO.File(GetExternalFilesDir(null), "derp.jpg");

            ISharedPreferences preference = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext);
            string             appVersion = PackageManager.GetPackageInfo(PackageName, Android.Content.PM.PackageInfoFlags.Activities).VersionName;

            if (!preference.Contains("cascade-data-version") || !preference.GetString("cascade-data-version", null).Equals(appVersion) ||
                !(preference.Contains("cascade-eye-data-path") || preference.Contains("cascade-face-data-path")))
            {
                AndroidFileAsset.OverwriteMethod overwriteMethod = AndroidFileAsset.OverwriteMethod.AlwaysOverwrite;

                FileInfo eyeFile  = AndroidFileAsset.WritePermanantFileAsset(this, "haarcascade_eye.xml", "cascade", overwriteMethod);
                FileInfo faceFile = AndroidFileAsset.WritePermanantFileAsset(this, "haarcascade_frontalface_alt_tree.xml", "cascade", overwriteMethod);

                Log.Error(TAG, "\t\t --eyeFile.FullName: " + eyeFile.FullName);
                Log.Error(TAG, "\t\t --faceFile.FullName: " + faceFile.FullName);

                //save tesseract data path
                ISharedPreferencesEditor editor = preference.Edit();
                editor.PutString("cascade-data-version", appVersion);
                editor.PutString("cascade-eye-data-path", eyeFile.FullName);
                editor.PutString("cascade-face-data-path", faceFile.FullName);
                editor.Commit();
            }

            eyeXml  = preference.GetString("cascade-eye-data-path", null);
            faceXml = preference.GetString("cascade-face-data-path", null);

            Log.Error(TAG, "\t\t --eyeXml: " + eyeXml);
            Log.Error(TAG, "\t\t --faceXml: " + faceXml);

            //face = new CascadeClassifier(faceXml);
            //eye = new CascadeClassifier(eyeXml);

            // Hide the window title and go fullscreen.
            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.AddFlags(WindowManagerFlags.Fullscreen);

            SetContentView(Resource.Layout.take_photo_surface_view);
            mTextureView     = (AutoFitTextureView)FindViewById(Resource.Id.CameraView);
            mTransparentView = (SurfaceView)FindViewById(Resource.Id.TransparentView);

            mTransparentView.SetZOrderOnTop(true);
            mTransparentView.BringToFront();

            mTransparentView.Holder.SetFormat(Android.Graphics.Format.Transparent);
            mTransparentView.Holder.AddCallback(this);

            var manager = GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            var size    = new Android.Graphics.Point();

            manager.DefaultDisplay.GetSize(size);

            screenX = size.X / 2;
            screenY = size.Y / 2;

            L = screenX - 200;
            T = screenY - 200;
            R = screenX + 200;
            B = screenY + 200;

            mStateCallback = new CameraStateListener()
            {
                owner = this
            };
            mSurfaceTextureListener   = new Camera2BasicSurfaceTextureListener(this);
            mOnImageAvailableListener = new ImageAvailableListener()
            {
                Owner = this
            };

            // fill ORIENTATIONS list
            ORIENTATIONS.Append((int)SurfaceOrientation.Rotation0, 90);
            ORIENTATIONS.Append((int)SurfaceOrientation.Rotation90, 0);
            ORIENTATIONS.Append((int)SurfaceOrientation.Rotation180, 270);
            ORIENTATIONS.Append((int)SurfaceOrientation.Rotation270, 180);
        }
Beispiel #26
0
 public PointTarget(int x, int y)
 {
     mPoint = new Point(x, y);
 }
Beispiel #27
0
        // Sets up member variables related to camera.
        private void SetUpCameraOutputs(int width, int height)
        {
            var activity = Activity;
            var manager  = (CameraManager)activity.GetSystemService(Context.CameraService);

            try
            {
                for (var i = 0; i < manager.GetCameraIdList().Length; i++)
                {
                    var cameraId = manager.GetCameraIdList()[i];
                    CameraCharacteristics characteristics = manager.GetCameraCharacteristics(cameraId);

                    // We don't use a front facing camera in this sample.
                    var facing = (Integer)characteristics.Get(CameraCharacteristics.LensFacing);
                    if (facing != null && facing == (Integer.ValueOf((int)LensFacing.Back)))
                    {
                        continue;
                    }

                    var map = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
                    if (map == null)
                    {
                        continue;
                    }

                    Size largest = (Size)Collections.Max(Arrays.AsList(map.GetOutputSizes((int)ImageFormatType.Jpeg)), new CompareSizesByArea());
                    mImageReader = ImageReader.NewInstance(largest.Width, largest.Height, ImageFormatType.Jpeg, /*maxImages*/ 2);
                    mImageReader.SetOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);

                    Point displaySize = new Point();
                    activity.WindowManager.DefaultDisplay.GetSize(displaySize);
                    var rotatedPreviewWidth  = height;
                    var rotatedPreviewHeight = width;
                    var maxPreviewWidth      = displaySize.Y;
                    var maxPreviewHeight     = displaySize.X;


                    // Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
                    // bus' bandwidth limitation, resulting in gorgeous previews but the storage of
                    // garbage capture data.
                    mPreviewSize = ChooseOptimalSize(map.GetOutputSizes(Class.FromType(typeof(SurfaceTexture))),
                                                     rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
                                                     maxPreviewHeight, largest);

                    // We fit the aspect ratio of TextureView to the size of preview we picked.
                    mTextureView.SetAspectRatio(mPreviewSize.Height, mPreviewSize.Width);

                    // Check if the flash is supported.
                    var available = (Boolean)characteristics.Get(CameraCharacteristics.FlashInfoAvailable);
                    if (available == null)
                    {
                        mFlashSupported = false;
                    }
                    else
                    {
                        mFlashSupported = (bool)available;
                    }

                    mCameraId = cameraId;
                    return;
                }
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
            catch (NullPointerException e)
            {
                // Currently an NPE is thrown when the Camera2API is used but not supported on the
                // device this code runs.
                //ErrorDialog.NewInstance(GetString(Resource.String.camera_error)).Show(ChildFragmentManager, FRAGMENT_DIALOG);
            }
        }
Beispiel #28
0
 public Point ToScreen(Coordinate p)
 {
     AG.Point point = NativeView.Map.Projection.ToScreenLocation(p.ToNative());
     return(new Point(point.X, point.Y));
 }
Beispiel #29
0
 public Coordinate ToCoordinate(Point p)
 {
     AG.Point point = new AG.Point((int)p.X, (int)p.Y);
     return(NativeView.Map.Projection.FromScreenLocation(point).ToUnity());
 }
Beispiel #30
0
        // Sets up member variables related to camera.
        private void SetUpCameraOutputs(int width, int height)
        {
            var activity = Activity;
            var manager  = (CameraManager)activity.GetSystemService(Context.CameraService);

            try
            {
                for (var i = 0; i < manager.GetCameraIdList().Length; i++)
                {
                    var cameraId = manager.GetCameraIdList()[i];
                    CameraCharacteristics characteristics = manager.GetCameraCharacteristics(cameraId);

                    // We don't use a front facing camera in this sample.
                    var facing = (Integer)characteristics.Get(CameraCharacteristics.LensFacing);
                    if (facing != null && facing == (Integer.ValueOf((int)LensFacing.Front)))
                    {
                        continue;
                    }

                    var map = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics
                                                                          .ScalerStreamConfigurationMap);
                    if (map == null)
                    {
                        continue;
                    }

                    // Find out if we need to swap dimension to get the preview size relative to sensor
                    // coordinate.
                    var displayRotation = activity.WindowManager.DefaultDisplay.Rotation;
                    //noinspection ConstantConditions
                    mSensorOrientation = (int)characteristics.Get(CameraCharacteristics.SensorOrientation);
                    bool swappedDimensions = false;
                    switch (displayRotation)
                    {
                    case SurfaceOrientation.Rotation0:
                    case SurfaceOrientation.Rotation180:
                        if (mSensorOrientation == 90 || mSensorOrientation == 270)
                        {
                            swappedDimensions = true;
                        }

                        break;

                    case SurfaceOrientation.Rotation90:
                    case SurfaceOrientation.Rotation270:
                        if (mSensorOrientation == 0 || mSensorOrientation == 180)
                        {
                            swappedDimensions = true;
                        }

                        break;

                    default:
                        Log.Error(TAG, "Display rotation is invalid: " + displayRotation);
                        break;
                    }

                    Point displaySize = new Point();
                    activity.WindowManager.DefaultDisplay.GetSize(displaySize);
                    var rotatedPreviewWidth  = width;
                    var rotatedPreviewHeight = height;
                    var maxPreviewWidth      = displaySize.X;
                    var maxPreviewHeight     = displaySize.Y;

                    if (swappedDimensions)
                    {
                        rotatedPreviewWidth  = height;
                        rotatedPreviewHeight = width;
                        maxPreviewWidth      = displaySize.Y;
                        maxPreviewHeight     = displaySize.X;
                    }

                    if (maxPreviewWidth > MAX_PREVIEW_WIDTH)
                    {
                        maxPreviewWidth = MAX_PREVIEW_WIDTH;
                    }

                    if (maxPreviewHeight > MAX_PREVIEW_HEIGHT)
                    {
                        maxPreviewHeight = MAX_PREVIEW_HEIGHT;
                    }

                    // Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
                    // bus' bandwidth limitation, resulting in gorgeous previews but the storage of
                    // garbage capture data.
                    mPreviewSize = new Size(960, 540);

                    // Check if the flash is supported.
                    var available = (Boolean)characteristics.Get(CameraCharacteristics.FlashInfoAvailable);
                    if (available == null)
                    {
                        mFlashSupported = false;
                    }
                    else
                    {
                        mFlashSupported = (bool)available;
                    }

                    mCameraId = cameraId;
                    return;
                }
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
            catch (NullPointerException e)
            {
                // Currently an NPE is thrown when the Camera2API is used but not supported on the
                // device this code runs.
                ErrorDialog.NewInstance(GetString(Resource.String.camera_error))
                .Show(ChildFragmentManager, FRAGMENT_DIALOG);
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            //opencv preferences
            AppPreference appPreference = new AppPreference();

            CvInvoke.UseOpenCL = false; // appPreference.UseOpenCL;
            System.String oclDeviceName = appPreference.OpenClDeviceName;
            if (!System.String.IsNullOrEmpty(oclDeviceName))
            {
                Log.Error(TAG, "\t\t --OclSetDefaultDevice: " + oclDeviceName);
                CvInvoke.OclSetDefaultDevice(oclDeviceName);
            }

            ISharedPreferences preference = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext);

            System.String appVersion = PackageManager.GetPackageInfo(PackageName, Android.Content.PM.PackageInfoFlags.Activities).VersionName;
            if (!preference.Contains("cascade-data-version") || !preference.GetString("cascade-data-version", null).Equals(appVersion) ||
                !(preference.Contains("cascade-eye-data-path") || preference.Contains("cascade-face-data-path")))
            {
                AndroidFileAsset.OverwriteMethod overwriteMethod = AndroidFileAsset.OverwriteMethod.AlwaysOverwrite;

                FileInfo eyeFile  = AndroidFileAsset.WritePermanantFileAsset(this, "haarcascade_eye.xml", "cascade", overwriteMethod);
                FileInfo faceFile = AndroidFileAsset.WritePermanantFileAsset(this, "haarcascade_frontalface_default.xml", "cascade", overwriteMethod);

                Log.Error(TAG, "\t\t --eyeFile.FullName: " + eyeFile.FullName);
                Log.Error(TAG, "\t\t --faceFile.FullName: " + faceFile.FullName);

                //save tesseract data path
                ISharedPreferencesEditor editor = preference.Edit();
                editor.PutString("cascade-data-version", appVersion);
                editor.PutString("cascade-eye-data-path", eyeFile.FullName);
                editor.PutString("cascade-face-data-path", faceFile.FullName);
                editor.Commit();
            }

            eyeXml  = preference.GetString("cascade-eye-data-path", null);
            faceXml = preference.GetString("cascade-face-data-path", null);

            Log.Error(TAG, "\t\t --eyeXml: " + eyeXml);
            Log.Error(TAG, "\t\t --faceXml: " + faceXml);

            // Hide the window title and go fullscreen.
            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.AddFlags(WindowManagerFlags.Fullscreen);

            SetContentView(Resource.Layout.take_photo_surface_view);
            //SurfaceView mSV = (SurfaceView)FindViewById(Resource.Id.CameraView);
            //mTextureView = (AutoFitTextureView)FindViewById(Resource.Id.CameraView);
            mTransparentView = (SurfaceView)FindViewById(Resource.Id.TransparentView);

            mTransparentView.SetZOrderOnTop(true);
            mTransparentView.BringToFront();

            mTransparentView.Holder.SetFormat(Android.Graphics.Format.Transparent);
            mTransparentView.Holder.AddCallback(this);

            var manager = GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            var size    = new Android.Graphics.Point();

            manager.DefaultDisplay.GetSize(size);

            screenX = size.X / 2;
            screenY = size.Y / 2;

            L = screenX - 100;
            T = screenY - 100;
            R = screenX + 100;
            B = screenY + 100;
        }
Beispiel #32
0
        public void UpdateUI()
        {
            if (CurrentRun != null && !CurrentRun.Active)
            {
                mRunLocations = mRunManager.GetLocationsForRun(CurrentRun.Id);

                if (mRunLocations.Count > 0)
                {
                    mStartedTextView.Text = CurrentRun.StartDate.ToLocalTime().ToString();

                    mLatitudeTextView.Text  = mRunLocations[0].Latitude.ToString();
                    mLongitudeTextView.Text = mRunLocations[0].Longitude.ToString();
                    mAltitudeTextView.Text  = mRunLocations[0].Altitude.ToString();

                    int durationSeconds = (int)Math.Ceiling((mRunLocations[mRunLocations.Count - 1].Time - CurrentRun.StartDate).TotalSeconds);
                    mDurationTextView.Text = Run.FormatDuration(durationSeconds);

//					var location = new LatLng(mRunLocations[mRunLocations.Count -1].Latitude, mRunLocations[mRunLocations.Count -1].Longitude);
//					var cu = CameraUpdateFactory.NewLatLngZoom (location, 20);
//					mGoogleMap.MoveCamera (cu);
                    DrawRunTrack(false);
                }
                else
                {
                    var     toast   = Toast.MakeText(Activity, Resource.String.empty_run_message, ToastLength.Long);
                    Display display = Activity.WindowManager.DefaultDisplay;
                    var     size    = new Android.Graphics.Point();
                    display.GetSize(size);
                    toast.SetGravity(GravityFlags.Top, 0, size.Y / 6);
                    toast.Show();
                }

                if (mRunManager.IsTrackingRun())
                {
                    mStartButton.Enabled    = false;
                    mStartButton.Visibility = ViewStates.Invisible;
                    mStopButton.Enabled     = false;
                    mStopButton.Visibility  = ViewStates.Invisible;
                }
                else
                {
                    mStartButton.Enabled = true;
                    mStopButton.Enabled  = false;
                }
            }
            else
            {
                bool started = mRunManager.IsTrackingRun();

                if (CurrentRun != null)
                {
                    mRunLocations         = mRunManager.GetLocationsForRun(CurrentRun.Id);
                    mStartedTextView.Text = CurrentRun.StartDate.ToLocalTime().ToString();
                }

                int durationSeconds = 0;
                if (CurrentRun != null && LastLocation != null)
                {
                    DateTime lastLocTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(LastLocation.Time);
                    durationSeconds         = CurrentRun.GetDurationSeconds(lastLocTime);
                    mLatitudeTextView.Text  = LastLocation.Latitude.ToString();
                    mLongitudeTextView.Text = LastLocation.Longitude.ToString();
                    mAltitudeTextView.Text  = LastLocation.Altitude.ToString();
                    mDurationTextView.Text  = Run.FormatDuration(durationSeconds);
                    CurrentRun.Duration     = durationSeconds;
                    mRunManager.UpdateItem <Run>(CurrentRun);

//					var location = new LatLng(LastLocation.Latitude, LastLocation.Longitude);
//					var cu = CameraUpdateFactory.NewLatLngZoom (location, 20);
//					mGoogleMap.MoveCamera (cu);
                    DrawRunTrack(true);
                }

                mStartButton.Enabled = !started;
                mStopButton.Enabled  = started;
            }
        }
Beispiel #33
0
 public static Point ToEto(this ag.Point point)
 {
     return(new Point(point.X, point.Y));
 }
Beispiel #34
0
 public PointTarget(Point point)
 {
     mPoint = point;
 }
        private IList<GeoPoint> Simplify(IList<Point> points, IList<GeoPoint> data, int epsilon)
        {
            var output = new List<GeoPoint>();

            var stack = new Stack<int[]>();
            var start = 0;
            var end = data.Count - 1;

            stack.Push(GetIndices(start, end));

            var indices = new List<int>();
            indices.Add(start);
            indices.Add(end);
            var pout = new Point();
            while (stack.Count != 0)
            {
                int[] startEnd = stack.Pop();
                start = startEnd[0];
                end = startEnd[1];

                reuse.Push(startEnd);
                if (start + 1 < end)
                {
                    int maxDistance = 0;
                    int farthestIndex = 0;

                    var startPoint = points[start];
                    var endPoint =  points[end];
                    for (int i = start + 1; i < end; i++)
                    {
                        var p =  points[i];
                        Util.ClosestPoint(p, startPoint, endPoint, pout );
                        int dist = Util.DistanceSquared(p.X, p.X, pout.X, pout.Y);
                        if (dist > maxDistance)
                        {
                            maxDistance = dist;
                            farthestIndex = i;
                        }
                    }
                    if (maxDistance > epsilon)
                    {
                        indices.Add(farthestIndex);
                        int[] indices1 = GetIndices(start, farthestIndex);
                        int[] indices2 = GetIndices(farthestIndex, end);

                        stack.Push(indices1);
                        stack.Push(indices2);
                    }
                }
            }

            Collections.Sort(indices);
            int previous = -1;
            foreach (var index in indices)
            {
                var i = index;
                if (i != previous)
                {
                    output.Add(data[i]);
                    previous = i;
                }
            }

            return output;
        }
Beispiel #36
0
        // Sets up member variables related to camera.
        private void SetUpCameraOutputs(int width, int height)
        {
            var manager = (CameraManager)_context.GetSystemService(Context.CameraService);

            try
            {
                for (var i = 0; i < manager.GetCameraIdList().Length; i++)
                {
                    var cameraId = manager.GetCameraIdList()[i];
                    CameraCharacteristics characteristics = manager.GetCameraCharacteristics(cameraId);

                    // We don't use a front facing camera in this sample.
                    var facing = (Integer)characteristics.Get(CameraCharacteristics.LensFacing);
                    if (facing != null && facing == (Integer.ValueOf((int)LensFacing.Front)))
                    {
                        continue;
                    }

                    var map = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
                    if (map == null)
                    {
                        continue;
                    }

                    // For still image captures, we use the largest available size.
                    Size largest = (Size)Collections.Max(Arrays.AsList(map.GetOutputSizes((int)ImageFormatType.Jpeg)),
                                                         new CompareSizesByArea());
                    mImageReader = ImageReader.NewInstance(largest.Width, largest.Height, ImageFormatType.Jpeg, /*maxImages*/ 2);
                    mImageReader.SetOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);
                    videoSize = ChooseVideoSize(map.GetOutputSizes(Class.FromType(typeof(MediaRecorder))));
                    // Find out if we need to swap dimension to get the preview size relative to sensor
                    // coordinate.
                    var windowManager   = _context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
                    var displayRotation = windowManager.DefaultDisplay.Rotation;
                    //noinspection ConstantConditions
                    mSensorOrientation = (int)characteristics.Get(CameraCharacteristics.SensorOrientation);
                    bool swappedDimensions = false;
                    switch (displayRotation)
                    {
                    case SurfaceOrientation.Rotation0:
                    case SurfaceOrientation.Rotation180:
                        if (mSensorOrientation == 90 || mSensorOrientation == 270)
                        {
                            swappedDimensions = true;
                        }
                        break;

                    case SurfaceOrientation.Rotation90:
                    case SurfaceOrientation.Rotation270:
                        if (mSensorOrientation == 0 || mSensorOrientation == 180)
                        {
                            swappedDimensions = true;
                        }
                        break;

                    default:
                        Log.Error(TAG, "Display rotation is invalid: " + displayRotation);
                        break;
                    }

                    Android.Graphics.Point displaySize = new Android.Graphics.Point();
                    windowManager.DefaultDisplay.GetSize(displaySize);
                    var rotatedPreviewWidth  = width;
                    var rotatedPreviewHeight = height;
                    var maxPreviewWidth      = displaySize.X;
                    var maxPreviewHeight     = displaySize.Y;
                    if (swappedDimensions)
                    {
                        rotatedPreviewWidth  = height;
                        rotatedPreviewHeight = width;
                        maxPreviewWidth      = displaySize.Y;
                        maxPreviewHeight     = displaySize.X;
                    }
                    if (maxPreviewWidth > MAX_PREVIEW_WIDTH)
                    {
                        maxPreviewWidth = MAX_PREVIEW_WIDTH;
                    }
                    if (maxPreviewHeight > MAX_PREVIEW_HEIGHT)
                    {
                        maxPreviewHeight = MAX_PREVIEW_HEIGHT;
                    }
                    // Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
                    // bus' bandwidth limitation, resulting in gorgeous previews but the storage of
                    // garbage capture data.
                    mPreviewSize = ChooseOptimalSize(map.GetOutputSizes(Class.FromType(typeof(SurfaceTexture))),
                                                     rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
                                                     maxPreviewHeight, largest);

                    // We fit the aspect ratio of TextureView to the size of preview we picked.
                    var orientation = Resources.Configuration.Orientation;
                    if (orientation == Android.Content.Res.Orientation.Landscape)
                    {
                        mTextureView.SetAspectRatio(mPreviewSize.Width, mPreviewSize.Height);
                    }
                    else
                    {
                        mTextureView.SetAspectRatio(mPreviewSize.Height, mPreviewSize.Width);
                    }
                    // Check if the flash is supported.
                    var available = (Java.Lang.Boolean)characteristics.Get(CameraCharacteristics.FlashInfoAvailable);
                    if (available == null)
                    {
                        mFlashSupported = false;
                    }
                    else
                    {
                        mFlashSupported = (bool)available;
                    }
                    mCameraId = cameraId;
                    return;
                }
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
            catch (NullPointerException)
            {
                // Currently an NPE is thrown when the Camera2API is used but not supported on the
                // device this code runs.
                ///ErrorDialog.NewInstance(GetString(Resource.String.camera_error)).Show(ChildFragmentManager, FRAGMENT_DIALOG);
            }
        }
Beispiel #37
0
 protected double angleBetween(Android.Graphics.Point p1, Point p2)
 {
     return(Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) + 1.57079633);
 }
Beispiel #38
0
 public static XIR.Point RemoteRepresentation(this AG.Point point)
 => new XIR.Point(point.X, point.Y);
Beispiel #39
0
		public PointF TransformPoint(Point p)
		{
			var px = new ag.Point[] { Conversions.ToAndroidPoint(p) };

#if TODO
			this.Control.TransformPoints(px);

			return Platform.Conversions.ToEto(px[0]);
#else 
			throw new NotImplementedException();
#endif
		}
 public VideoStreamsView(Context c, Point screenDimensions)
     : base(c)
 {
     this.screenDimensions = screenDimensions;
     PreserveEGLContextOnPause = true;
     SetEGLContextClientVersion(2);
     SetRenderer(this);
     RenderMode = Rendermode.WhenDirty;
 }