Example #1
0
        public bool Detect(Color[] data, int targ_cx, int targ_cy, int targ_halfWidth, out int pID)
        {
            lock (playerCalibs)
            {
                pID = -1;
                ColorDetector detector = new ColorDetector(w, h);
                YCbCrColor avgColor = detector.GetAvgColor(data, targ_cx, targ_cy, targ_halfWidth);

                var canidates = playerCalibs.Where(calib =>
                    {
                        if (calib.Key == _pID) return false;

                        detector.LoadFromCalibration(calib.Value);
                        return detector.DetectThresh(data, targ_cx, targ_cy, targ_halfWidth);
                    }).OrderBy(calib => calib.Value.DistanceSqTo(avgColor));

                if (canidates.Any())
                {
                    pID = canidates.First().Key;
                    return true;
                }
                else
                    return false;
            }
        }
Example #2
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            capcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
            capcam.DesiredFormat = capcam.SupportedFormats.First(f => f.PixelWidth == w);

            captureSource = new CaptureSource();
            captureSource.VideoCaptureDevice = capcam;
            captureSource.Start();

            sink = new FrameVideoSink();
            sink.CaptureSource = captureSource;
            sink.OnFrameReady += sink_OnFrameReady;
            sink.Enabled = true;

            viewfinderBrush.SetSource(captureSource);
            viewfinderBrush.Stretch = Stretch.Fill;

            renderBmp = new WriteableBitmap(w, h);
            renderBrush.ImageSource = renderBmp;

            phocam = new PhotoCamera();

            detector = new ColorDetector(w, h);
        }