public static void Capture(IntPtr hwnd, Direct3DVersion direct3DVersion = Direct3DVersion.AUTO_DETECT)
        {
            NativeUtils.GetWindowThreadProcessId(hwnd, out var processID);
            var process = Process.GetProcessById(processID);

            var captureConfig = new CaptureConfig
            {
                Direct3DVersion       = direct3DVersion,
                ShowOverlay           = true,
                CaptureMouseEvents    = true,
                CaptureKeyboardEvents = true
            };

            var captureInterface = new CaptureInterface();

            captureInterface.RemoteMessage += e =>
            {
                Debug.WriteLine(e.Message);
            };

            captureInterface.Connected += () =>
            {
                captureInterface.DrawOverlayInGame(new Overlay
                {
                    Elements = new List <IOverlayElement>
                    {
                        new RectangleElement
                        {
                            Colour   = Color.FromArgb(Color.Gray.ToArgb() ^ (0x33 << 24)),
                            Location = new Point(0, 0),
                            Width    = -1,
                            Height   = -1
                        },
                        new RectangleMouseHookElement
                        {
                            Colour = Color.FromArgb(Color.Green.ToArgb() ^ (0x33 << 24)),
                            Width  = 0,
                            Height = 0
                        },
                        new FramesPerSecond(new Font("Arial", 16, FontStyle.Bold))
                        {
                            Location    = new Point(0, 0),
                            Color       = Color.Red,
                            AntiAliased = true,
                            Text        = "{0:N0} FPS"
                        }
                    },
                    Hidden = false
                });
            };

            var captureProcess = new CaptureProcess(process, captureConfig, captureInterface);

            while (!captureProcess.IsDisposed)
            {
                Thread.Sleep(500);
            }

            Debug.WriteLine("Disconnected from DirectX Hook");
        }
Exemple #2
0
        /// <summary>
        /// c# implementation of https://github.com/robidouille/robidouille/blob/master/raspicam_cv/RaspiCamTest.c
        /// </summary>
        public void Run()
        {
            Log.Info("Creating Window");
            var windowName = "PiCamCVSimpleTest";

            CvInvoke.NamedWindow(windowName); //Create the window using the specific name

            Log.Info("Creating capture");

            EnvironmentService.DemandUnix("OpenCV 3.0 deprecated these capture methods. Only supported with PiCamCv on Pi");
            var captureConfig = new CaptureConfig {
                Resolution = new Resolution(640, 480), Framerate = 25, Monochrome = true
            };
            var piConfig = PiCameraConfig.FromConfig(captureConfig);

            IntPtr capture = CvInvokeRaspiCamCV.cvCreateCameraCapture2(0, ref piConfig); // Index doesn't really matter

            do
            {
                IntPtr imagePtr = CvInvokeRaspiCamCV.cvQueryFrame(capture);
                using (var managedImage = Image <Bgr, Byte> .FromIplImagePtr(imagePtr))
                {
                    CvInvoke.Imshow(windowName, managedImage);
                }
            } while (CvInvoke.WaitKey(100) < 0);

            CvInvoke.DestroyWindow("RaspiCamTest");
            CvInvokeRaspiCamCV.cvReleaseCapture(ref capture);
        }
Exemple #3
0
        private static ICaptureGrab BuildCaptureGrabber(CaptureConfig config = null)
        {
            var request = new CaptureRequest {
                Device = CaptureDevice.Usb
            };

            if (EnvironmentService.IsUnix)
            {
                request.Device = CaptureDevice.Pi;
            }

            if (config == null)
            {
                // Default capture
                request.Config = new CaptureConfig {
                    Resolution = new Resolution(160, 120), Framerate = 50, Monochrome = false
                };
            }

            var capture      = CaptureFactory.GetCapture(request);
            var actualConfig = capture.GetCaptureProperties();

            Log.Info($"Created capture: {actualConfig}");

            SafetyCheckRoi(_consoleOptions, actualConfig);
            return(capture);
        }
Exemple #4
0
 ///<summary> Create a capture using the specific camera</summary>
 ///<param name="camIndex"> The index of the camera to create capture from, starting from 0</param>
 private CapturePi(int camIndex, CaptureConfig config)
 {
     CaptureSource = CaptureModuleType.Camera;
     InitOpenCV();
     InitCapture(camIndex, PiCameraConfig.FromConfig(config));
     RequestedConfig = config;
 }
Exemple #5
0
 private void checkCleanup()
 {
     if (Input.GetKeyDown(CaptureConfig.GetCleanupKey()))
     {
         SceneManager.LoadScene("CleanupEC");
     }
 }
        public EntryPoint(
            EasyHook.RemoteHooking.IContext context,
            String channelName,
            CaptureConfig config)
        {
            // Get reference to IPC to host application
            // Note: any methods called or events triggered against _interface will execute in the host process.
            _interface = EasyHook.RemoteHooking.IpcConnectClient <CaptureInterface>(channelName);

            // We try to ping immediately, if it fails then injection fails
            _interface.Ping();

            #region Allow client event handlers (bi-directional IPC)

            // Attempt to create a IpcServerChannel so that any event handlers on the client will function correctly
            System.Collections.IDictionary properties = new System.Collections.Hashtable();
            properties["name"]     = channelName;
            properties["portName"] = channelName + Guid.NewGuid().ToString("N"); // random portName so no conflict with existing channels of channelName

            System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider binaryProv = new System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider();
            binaryProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            System.Runtime.Remoting.Channels.Ipc.IpcServerChannel _clientServerChannel = new System.Runtime.Remoting.Channels.Ipc.IpcServerChannel(properties, binaryProv);
            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(_clientServerChannel, false);

            #endregion
        }
        public AutoCaptureEngine(
            IEventAggregator events,
            [ImportMany] IEnumerable <IImageScanner> imageScanners)
        {
            this.events        = events;
            this.imageScanners = imageScanners;
            this.screenCapture = new ScreenCapture();
            var direct3DVersion = Direct3DVersion.Direct3D9SharedMem;

            CaptureMethod      = CaptureMethod.AutoDetect;
            this.captureConfig = new CaptureConfig()
            {
                Direct3DVersion = direct3DVersion
            };
            var security = new MutexSecurity();

            security.AddAccessRule(new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.Synchronize | MutexRights.Modify, AccessControlType.Allow));
            bool created;

            sharedMemMutexes = new[]
            {
                new Mutex(false, "Global\\DXHookD3D9Shared0", out created, security),
                new Mutex(false, "Global\\DXHookD3D9Shared1", out created, security)
            };
            var ewsecurity = new EventWaitHandleSecurity();

            ewsecurity.AddAccessRule(new EventWaitHandleAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), EventWaitHandleRights.FullControl, AccessControlType.Allow));
            captureDxWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, "Global\\DXHookD3D9Capture", out created, ewsecurity);
            hookReadyWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, "Global\\DXHookD3D9CaptureReady", out created, ewsecurity);
        }
        /// <summary>
        /// sudo mono picamcv.con.exe -m=pantiltmultimode
        /// </summary>
        public MultimodePanTiltController(
            IPanTiltMechanism panTiltMech
            , CaptureConfig captureConfig
            , IScreen screen
            , IServerToCameraBus serverToCameraBus
            , params IOutputProcessor[] outputPipelines) : base(panTiltMech, captureConfig)
        {
            _screen            = screen;
            _serverToCameraBus = serverToCameraBus;
            _outputPipelines   = outputPipelines;

            _faceTrackingController     = new FaceTrackingPanTiltController(panTiltMech, captureConfig);
            _camshiftTrackingController = new CamshiftPanTiltController(panTiltMech, captureConfig);
            _colourTrackingController   = new ColourTrackingPanTiltController(panTiltMech, captureConfig);

            _thresholdSelector = new ThresholdSelector();
            _thresholdSelector.ColourCheckTick += thresholdSelector_ColourCheckTick;

            _colourDetectorInput = new ColourDetectorInput();
            _colourDetectorInput.SetCapturedImage    = true;
            _colourDetectorInput.Settings.MomentArea = new RangeF(50, 10000);

            _faceTrackManager   = new FaceTrackStateManager(screen);
            _colourTrackManager = new ColourTrackStateManager(screen);
            _autonomousManager  = new AutonomousTrackStateManager(this, screen);

            screen.Clear();
            SetMode(ProcessingMode.Autonomous);

            _autonomousManager.IsFaceFound       = i => _faceTrackingController.Process(i).IsDetected;
            _autonomousManager.IsColourFullFrame = IsColourFullFrame;

            InitController();
        }
Exemple #9
0
        private bool HookProcess(ProcStatus procStatus)
        {
            if (procStatus.ProcessId == 0)
            {
                return(false);
            }

            Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;
            CaptureConfig   cc = new CaptureConfig()
            {
                Direct3DVersion = direct3DVersion,
                ShowOverlay     = showFPSToolStripMenuItem.Checked
            };

            FileUnblocker.Unblock("EasyHook32Svc.exe");
            FileUnblocker.Unblock("EasyHook64Svc.exe");

            var captureInterface = new CaptureInterface();

            captureInterface.RemoteMessage += CaptureInterface_RemoteMessage;
            procStatus.CaptureProcess       = new CaptureProcess(procStatus.Process, cc, captureInterface);
            PrintStatus("* Hooked " + procStatus.Name);
            hookedProcesses.Add(procStatus.ProcessId, procStatus);
            AddExitHook(procStatus);
            return(true);
        }
Exemple #10
0
 public CaptureUsb(int index, CaptureConfig config)
     : base(new VideoCapture(index))
 {
     RequestedConfig = config;
     SetCaptureProperty(CapProp.FrameHeight, config.Resolution.Height);
     SetCaptureProperty(CapProp.FrameWidth, config.Resolution.Width);
     SetCaptureProperty(CapProp.Monochrome, config.Monochrome ? 1 : 0);
 }
        /// <summary>
        /// sudo mono picamcv.con.exe -m=pantiltmultimode
        /// </summary>
        public MultimodePanTiltController(
            IPanTiltMechanism panTiltMech
            , CaptureConfig captureConfig
            , IScreen screen
            , IServerToCameraBus serverToCameraBus
            , params IOutputProcessor[] outputPipelines) : base(panTiltMech, captureConfig)
        {
            _screen            = screen;
            _serverToCameraBus = serverToCameraBus;
            _outputPipelines   = outputPipelines;

            _colourSettingsRepository = new ColourSettingsRepository();

            _faceTrackingController     = new FaceTrackingPanTiltController(panTiltMech, captureConfig);
            _camshiftTrackingController = new CamshiftPanTiltController(panTiltMech, captureConfig);
            _colourTrackingController   = new ColourTrackingPanTiltController(panTiltMech, captureConfig);

            _thresholdSelector = new ThresholdSelector();
            _thresholdSelector.ColourCheckTick += thresholdSelector_ColourCheckTick;

            _colourDetectorInput = new ColourDetectorInput();
            _colourDetectorInput.SetCapturedImage = true;
            var repoSettings = _colourSettingsRepository.Read();

            if (repoSettings != null)
            {
                _colourDetectorInput.Settings = repoSettings;
            }

            _faceTrackManager   = new FaceTrackStateManager(screen);
            _colourTrackManager = new ColourTrackStateManager(screen);
            _staticManager      = new StaticStateManager(screen);
            _autonomousManager  = new AutonomousTrackStateManager(this, screen);

            SoundService = new SoundService();


            screen.Clear();
            ChangeMode(ProcessingMode.Autonomous);

            _autonomousManager.IsFaceFound       = i => _faceTrackingController.Process(i).IsDetected;
            _autonomousManager.IsColourFullFrame = IsColourFullFrame;

            _faceTrackingController.ClassifierParams.MinSize = new Size(20, 20);
            _faceTrackingController.ClassifierParams.MaxSize = new Size(50, 50);

            screen.WriteLine(_faceTrackingController.ClassifierParams.ToString());

            InitController();

            ServoSettleTimeChanged += (s, e) =>
            {
                _faceTrackingController.ServoSettleTime   = ServoSettleTime;
                _colourTrackingController.ServoSettleTime = ServoSettleTime;
            };

            _colourDetector = new ColourDetector();
        }
        public FaceTrackingPanTiltController(IPanTiltMechanism panTiltMech, CaptureConfig captureConfig)
            : base(panTiltMech, captureConfig)
        {
            var environmentService = new EnvironmentService();
            var haarEyeFile        = new FileInfo(environmentService.GetAbsolutePathFromAssemblyRelative("haarcascades/haarcascade_eye.xml"));
            var haarFaceFile       = new FileInfo(environmentService.GetAbsolutePathFromAssemblyRelative("haarcascades/haarcascade_frontalface_default.xml"));

            _faceDetector = new FaceDetector(haarFaceFile.FullName, haarEyeFile.FullName);
        }
Exemple #13
0
        /// <summary>
        ///     Prepares capturing in the target process. Note that the process must not already be hooked, and must have a
        ///     <see cref="Process.MainWindowHandle" />.
        /// </summary>
        /// <param name="process">The process to inject into</param>
        /// <exception cref="ProcessHasNoWindowHandleException">
        ///     Thrown if the <paramref name="process" /> does not have a window
        ///     handle. This could mean that the process does not have a UI, or that the process has not yet finished starting.
        /// </exception>
        /// <exception cref="ProcessAlreadyHookedException">Thrown if the <paramref name="process" /> is already hooked</exception>
        /// <exception cref="InjectionFailedException">Thrown if the injection failed - see the InnerException for more details.</exception>
        /// <remarks>The target process will have its main window brought to the foreground after successful injection.</remarks>
        public CaptureProcess(Process process, CaptureConfig config, CaptureInterface captureInterface)
        {
            // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
            if (process.MainWindowHandle == IntPtr.Zero)
            {
                throw new ProcessHasNoWindowHandleException();
            }

            // Skip if the process is already hooked (and we want to hook multiple applications)
            if (HookManager.IsHooked(process.Id))
            {
                throw new ProcessAlreadyHookedException();
            }

            captureInterface.ProcessId = process.Id;
            CaptureInterface           = captureInterface;
            //_serverInterface = new CaptureInterface() { ProcessId = process.Id };

            // Initialise the IPC server (with our instance of _serverInterface)
            _screenshotServer = RemoteHooking.IpcCreateServer(
                ref _channelName,
                WellKnownObjectMode.Singleton,
                CaptureInterface);

            try
            {
                // Inject DLL into target process
                RemoteHooking.Inject(
                    process.Id,
                    InjectionOptions.Default,
                    typeof(CaptureInterface).Assembly.Location,
                    //"Capture.dll", // 32-bit version (the same because AnyCPU) could use different assembly that links to 32-bit C++ helper dll
                    typeof(CaptureInterface).Assembly.Location,
                    //"Capture.dll", // 64-bit version (the same because AnyCPU) could use different assembly that links to 64-bit C++ helper dll
                    // the optional parameter list...
                    _channelName, // The name of the IPC channel for the injected assembly to connect to
                    config
                    );
            }
            catch (Exception e)
            {
                throw new InjectionFailedException(e);
            }

            HookManager.AddHookedProcess(process.Id);

            Process = process;

            // Ensure the target process is in the foreground,
            // this prevents an issue where the target app appears to be in
            // the foreground but does not receive any user inputs.
            // Note: the first Alt+Tab out of the target application after injection
            //       may still be an issue - switching between windowed and
            //       fullscreen fixes the issue however (see ScreenshotInjection.cs for another option)
            BringProcessWindowToFront();
        }
        public HandCalibratedModifierStrategy(CaptureConfig captureConfig, Point target) : base(captureConfig, target)
        {
            _regressorPair = new LinearRegressorFactory().GetHandMeasured320x240();

            // calibration was done in 320x240. If capture settings different need to scale the calibration
            decimal xDiffScale = captureConfig.Resolution.Width / 320m;
            decimal yDiffScale = captureConfig.Resolution.Height / 240m;

            Scale = new PointD(xDiffScale, yDiffScale);
        }
        public HandCalibratedModifierStrategy(CaptureConfig captureConfig, Point target)
            : base(captureConfig, target)
        {
            _regressorPair = new LinearRegressorFactory().GetHandMeasured320x240();

            // calibration was done in 320x240. If capture settings different need to scale the calibration
            decimal xDiffScale = captureConfig.Resolution.Width / 320m;
            decimal yDiffScale = captureConfig.Resolution.Height / 240m;

            Scale = new PointD(xDiffScale, yDiffScale);
        }
Exemple #16
0
        private void AttachProcess()
        {
            m_InjectButton.Enabled = false;

            string exeName = Path.GetFileNameWithoutExtension(((IBotInfo)m_BotInfoComboBox.SelectedItem).GetExecutableName);

            Process[] processes = Process.GetProcessesByName(exeName);
            if (processes.Length == 0)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
                m_InjectButton.Enabled = true;
                return;
            }

            Process process = processes[0];

            // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
            if (process.MainWindowHandle == IntPtr.Zero)
            {
                return;
            }

            // Skip if the process is already hooked (and we want to hook multiple applications)
            if (HookManager.IsHooked(process.Id))
            {
                return;
            }

            CaptureConfig cc = new CaptureConfig()
            {
                Direct3DVersion = Direct3DVersion.AutoDetect, ShowOverlay = true
            };

            //captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
            m_captureProcess = new CaptureProcess(process, cc, new CaptureInterface());

            Thread.Sleep(10);

            IBot.print("Creating and attaching script: " + ((IBotInfo)m_BotInfoComboBox.SelectedItem).ToString() + " by " + ((IBotInfo)m_BotInfoComboBox.SelectedItem).Author);
            m_Bot = ((IBotInfo)m_BotInfoComboBox.SelectedItem).CreateBot;
            m_Bot.OnAttach();

            m_InjectButton.Text               = "Detach";
            m_InjectButton.Enabled            = true;
            m_SteppingEnabledCheckbox.Checked = true;
            m_SteppingEnabledCheckbox.Enabled = true;

            myTimer.Tick    += new EventHandler(TimerEventProcessor);
            myTimer.Interval = 100;
            myTimer.Start();

            CaptureScreenshot();
        }
Exemple #17
0
 private static void SafetyCheckRoi(ConsoleOptions options, CaptureConfig captureProperties)
 {
     if (captureProperties.Resolution.IsValid && options.ColourSettings != null)
     {
         var roiWidthTooBig  = options.ColourSettings.Roi.Width > captureProperties.Resolution.Width;
         var roiHeightTooBig = options.ColourSettings.Roi.Height > captureProperties.Resolution.Height;
         if (roiWidthTooBig || roiHeightTooBig)
         {
             Log.Warn("ROI is too big! Ignoring");
             options.ColourSettings.Roi = Rectangle.Empty;
         }
     }
 }
Exemple #18
0
        private CaptureConfig HarvestFormCaptureConfig()
        {
            var config        = new CaptureConfig();
            var resComponents = cmbResolution.Text.Split('x');

            config.Resolution.Width  = Convert.ToInt32(resComponents[0]);
            config.Resolution.Height = Convert.ToInt32(resComponents[1]);
            config.Bitrate           = Convert.ToInt32(txtBitrate.Text);
            config.Framerate         = Convert.ToInt32(txtFramerate.Text);
            config.Monochrome        = chkMonochrome.Checked;

            return(config);
        }
Exemple #19
0
        public void AttachProcess()
        {
            Process[] processes = Process.GetProcessesByName("HuniePop 2 - Double Date");

            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = true
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                this.parent.launcHuniePop2Listener();
                hooked = false;
            }
            else
            {
                this.message.Foreground = new SolidColorBrush(Colors.DarkGreen);
                this.message.Text       = "Attached to game";
                hooked = true;
            }
        }
Exemple #20
0
        private void AttachProcess()
        {
            string exeName = "Bejeweled3";

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = cbDrawOverlay.Checked
                };

                capturing.ProcessId = process.Id;
                capturing.Process   = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                capturing.CaptureProcess        = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (capturing.CaptureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
            else
            {
                btnLoadTest.Enabled = true;
                btnCapture.Enabled  = true;
            }
        }
        /*
         *
         * CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds.
         * CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
         * CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file
         * CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
         * CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
         * CV_CAP_PROP_FPS Frame rate.
         * CV_CAP_PROP_FOURCC 4-character code of codec.
         * CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
         * CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
         * CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
         * CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
         * CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
         * CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
         * CV_CAP_PROP_HUE Hue of the image (only for cameras).
         * CV_CAP_PROP_GAIN Gain of the image (only for cameras).
         * CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
         * CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
         * CV_CAP_PROP_WHITE_BALANCE Currently unsupported
         * CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)
         *
         */
        public static CaptureConfig GetCaptureProperties(this ICaptureGrab capture)
        {
            if (capture == null)
            {
                return(null);
            }
            var settings = new CaptureConfig();

            settings.Resolution.Height = Convert.ToInt32(capture.GetCaptureProperty(CapProp.FrameHeight));
            settings.Resolution.Width  = Convert.ToInt32(capture.GetCaptureProperty(CapProp.FrameWidth));
            settings.Framerate         = Convert.ToInt32(capture.GetCaptureProperty(CapProp.Fps));
            settings.Monochrome        = Convert.ToBoolean(capture.GetCaptureProperty(CapProp.Monochrome));
            return(settings);
        }
        public bool HandleKeyPress(char key)
        {
            var handled       = true;
            var captureConfig = new CaptureConfig();

            switch (key)
            {
            case '7':
                captureConfig.Framerate  = 40;
                captureConfig.Resolution = new Resolution(128, 96);
                _serverToCameraBus.InvokeUpdateCapture(captureConfig);
                break;

            case '8':
                captureConfig.Framerate  = 60;
                captureConfig.Resolution = new Resolution(160, 120);
                _serverToCameraBus.InvokeUpdateCapture(captureConfig);
                break;

            case 'a':
                ForceMode(ProcessingMode.Autonomous);
                break;

            case 'f':
                ForceMode(ProcessingMode.FaceDetection);
                break;

            case 'c':
                ForceMode(ProcessingMode.ColourTrackFromFileSettings);
                break;

            case 'q':
                _screen.WriteLine($"P/T={CurrentSetting},M={State}");
                break;

            case 'r':
                var command = new PanTiltSettingCommand();
                command.Type        = PanTiltSettingCommandType.MoveAbsolute;
                command.PanPercent  = 50;
                command.TiltPercent = 50;
                HandleCommand(this, command);
                break;

            default:
                handled = false;
                break;
            }
            return(handled);
        }
Exemple #23
0
        public void StartHook()
        {
            var exeName = "GTA5";

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (var process in processes)
            {
                if (process == null)
                {
                    continue;
                }
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3dVersion = Direct3DVersion.Direct3D11;

                /*
                 * switch (gameSettings.Graphics.DX_Version.Value)
                 * {
                 *  case 0:
                 *      direct3dVersion = Direct3DVersion.Direct3D10;
                 *      break;
                 *  case 1:
                 *      direct3dVersion = Direct3DVersion.Direct3D10_1;
                 *      break;
                 *  case 2:
                 *      direct3dVersion = Direct3DVersion.Direct3D11;
                 *      break;
                 * }*/

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3dVersion,
                    ShowOverlay     = true,
                };

                _gtaProcessId = process.Id;
                _gtaProcess   = process;

                var captureInterface = new CaptureInterface();
                _captureProcess = new CaptureProcess(process, cc, captureInterface);
                //Thread.Sleep(5000);
                //_captureProcess.CaptureInterface.DisplayInGameText("HELLO FROM PLAYMultiV!", TimeSpan.FromSeconds(60));
                //_captureProcess.CaptureInterface.up
            }
        }
Exemple #24
0
        public void AddHooks()
        {
            if (HookManager.IsHooked(_process.Id))
            {
                return;
            }

            var captureConfig = new CaptureConfig {
                Direct3DVersion = Direct3DVersion.AutoDetect,
                ShowOverlay     = true
            };
            var captureInterface = new CaptureInterface();

            captureInterface.RemoteMessage += CaptureInterfaceOnRemoteMessage;
            _captureProcess = new CaptureProcess(_process, captureConfig, captureInterface);
        }
Exemple #25
0
        private void CreateCaptureProcess(Process process)
        {
            _process = process;

            Direct3DVersion direct3DVersion = Direct3DVersion.Direct3D10;

            if (rbDirect3D11.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D11;
            }
            else if (rbDirect3D10_1.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D10_1;
            }
            else if (rbDirect3D10.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D10;
            }
            else if (rbDirect3D9.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D9;
            }
            else if (rbAutodetect.Checked)
            {
                direct3DVersion = Direct3DVersion.AutoDetect;
            }

            var cc = new CaptureConfig
            {
                Direct3DVersion = direct3DVersion,
                ShowOverlay     = cbDrawOverlay.Checked,
                TestThisShit    = 300
            };

            var captureInterface = new CaptureInterface();

            if (frm2 != null)
            {
                frm2.Close();
                frm2.Dispose();
            }

            frm2 = new form2JT(captureInterface);

            captureInterface.RemoteMessage += CaptureInterface_RemoteMessage;
            _captureProcess = new CaptureProcess(process, cc, captureInterface);
        }
Exemple #26
0
        private void AttachProcess()
        {
            string exeName = Path.GetFileNameWithoutExtension("Europa_Client.exe");

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = true,
                    WallhackEnabled = checkBox1.Checked,
                    WeaponEnabled   = checkBox2.Checked
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
        }
 public AutoCalibratedModifierStrategy(CaptureConfig captureConfig, Point target)
     : base(captureConfig, target)
 {
     var readingsRepository = new CalibrationReadingsRepository();
     var readings = readingsRepository.Read();
     if (!readings.ContainsKey(captureConfig.Resolution))
     {
         readings.Add(captureConfig.Resolution, new AxesCalibrationReadings());
         Log.WarnFormat("Failed to load any calibration readings for {0}", captureConfig.Resolution);
     }
     _calibratedReadings = readings[captureConfig.Resolution];
     Log.InfoFormat(
         "Using {0} horizontal, {1} vertial calibration readings for {2}"
         , _calibratedReadings.Horizontal.Count
         , _calibratedReadings.Vertical.Count
         , captureConfig.Resolution);
 }
Exemple #28
0
        public void AttachProcess(string proc)
        {
            string exeName = Path.GetFileNameWithoutExtension(proc);

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;
                

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay = true
                };

                ProcessID = process.Id;
                Process = process;

                var captureInterface = new CaptureInterface();
                CaptureProcess = new CaptureProcess(process, cc, captureInterface);
                break;
            }
            Thread.Sleep(10);

            if (CaptureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
                Environment.Exit(0);
            }
        }
Exemple #29
0
        private void AttachProcess()
        {
            string exeName = Path.GetFileNameWithoutExtension(_config.HellbladeExecutablePath);

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = Direct3DVersion.AutoDetect,
                    ShowOverlay     = false
                };

                _process = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                throw new InvalidOperationException($"No executable found matching: '{exeName}''");
            }

            _isAttached = true;
        }
        public void CalculateNewSettingCalibratedResolution()
        {
            var target = new Point(160, 120);
            var objective = new Point(128, 120);
            var config = new CaptureConfig{Resolution = new Resolution(320, 240)};
            var strategy = new HandCalibratedModifierStrategy(config, target);

            strategy.Objective = objective;

            var setting = new PanTiltSetting(50,50);

            var newSetting = strategy.CalculateNewSetting(setting);

            // AssertBuilder.Generate(newSetting, "newSetting"); // The following assertions were generated on 07-Mar-2015
            #region CodeGen Assertions
            Assert.AreEqual(53.0720m, newSetting.PanPercent);
            Assert.AreEqual(50m, newSetting.TiltPercent);
            #endregion
        }
Exemple #31
0
        private void AttachProcess(string proc)
        {
            string exeName = Path.GetFileNameWithoutExtension(proc);

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = true
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                //captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage); //DEBUG
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
        }
Exemple #32
0
        public static void AttachProcess(string name)
        {
            if (CaptureProcess != null)
            {
                HookManager.RemoveHookedProcess(CaptureProcess.Process.Id);
                CaptureProcess.CaptureInterface.Disconnect();
                CaptureProcess = null;
            }

            try
            {
                Process[] processes = Process.GetProcessesByName(name);
                foreach (Process p in processes)
                {
                    if (p.MainWindowHandle == IntPtr.Zero)
                    {
                        continue;
                    }

                    if (HookManager.IsHooked(p.Id))
                    {
                        continue;
                    }

                    CaptureConfig cc = new CaptureConfig()
                    {
                        Direct3DVersion = Direct3DVersion.AutoDetect,
                        ShowOverlay     = true
                    };

                    var captureInterface = new CaptureInterface();
                    CaptureProcess = new CaptureProcess(p, cc, captureInterface);
                }

                Log.Write("Process attached: " + name + " (Width: " + Width + "; Height: " + Height + ")");
            }
            catch (Exception e)
            {
                Log.Write(e.Message);
            }
        }
        public void CalculateNewSettingCalibratedResolution()
        {
            var target    = new Point(160, 120);
            var objective = new Point(128, 120);
            var config    = new CaptureConfig {
                Resolution = new Resolution(320, 240)
            };
            var strategy = new HandCalibratedModifierStrategy(config, target);

            strategy.Objective = objective;

            var setting = new PanTiltSetting(50, 50);

            var newSetting = strategy.CalculateNewSetting(setting);

            // AssertBuilder.Generate(newSetting, "newSetting"); // The following assertions were generated on 07-Mar-2015
            #region CodeGen Assertions
            Assert.AreEqual(53.0720m, newSetting.PanPercent);
            Assert.AreEqual(50m, newSetting.TiltPercent);
            #endregion
        }
Exemple #34
0
        public static PiCameraConfig FromConfig(CaptureConfig config)
        {
            var s = new PiCameraConfig();

            if (config == null)
            {
                s.Width = 0;
                s.Height = 0;
                s.Bitrate = 0;
                s.Framerate = 0;
                s.Monochrome = 0;
            }
            else
            {
                s.Width = config.Resolution.Width;
                s.Height = config.Resolution.Height;
                s.Bitrate = config.Bitrate;
                s.Framerate = config.Framerate;
                s.Monochrome = config.Monochrome ? 1 : 0;
            }

            return s;
        }
Exemple #35
0
 public CaptureRequest()
 {
     Config = new CaptureConfig();
 }
Exemple #36
0
        private CaptureConfig HarvestFormCaptureConfig()
        {
            var config = new CaptureConfig();
            var resComponents = cmbResolution.Text.Split('x');
            config.Resolution.Width = Convert.ToInt32(resComponents[0]);
            config.Resolution.Height = Convert.ToInt32(resComponents[1]);
            config.Bitrate = Convert.ToInt32(txtBitrate.Text);
            config.Framerate = Convert.ToInt32(txtFramerate.Text);
            config.Monochrome = chkMonochrome.Checked;

            return config;
        }
Exemple #37
0
 public CaptureUsb(int index, CaptureConfig config)
     : base(new VideoCapture(index))
 {
     RequestedConfig = config;
     SetCaptureProperty(CapProp.FrameHeight,config.Resolution.Height);
     SetCaptureProperty(CapProp.FrameWidth, config.Resolution.Width);
     SetCaptureProperty(CapProp.Monochrome, config.Monochrome ? 1 : 0);
 }
Exemple #38
0
 public CaptureUsb(CaptureConfig config)
     : this(0, config)
 {
 }
Exemple #39
0
 public static void SetCaptureProperties(this ICaptureGrab capture, CaptureConfig properties)
 {
     capture.SetCaptureProperty(CapProp.FrameHeight, properties.Resolution.Height);
     capture.SetCaptureProperty(CapProp.FrameWidth,  properties.Resolution.Width);
     capture.SetCaptureProperty(CapProp.Monochrome, properties.Monochrome ? 1 : 0);
 }
Exemple #40
0
        /*
         *
        CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds.
        CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
        CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file
        CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
        CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
        CV_CAP_PROP_FPS Frame rate.
        CV_CAP_PROP_FOURCC 4-character code of codec.
        CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
        CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
        CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
        CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
        CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
        CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
        CV_CAP_PROP_HUE Hue of the image (only for cameras).
        CV_CAP_PROP_GAIN Gain of the image (only for cameras).
        CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
        CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
        CV_CAP_PROP_WHITE_BALANCE Currently unsupported
        CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)

         */
        public static CaptureConfig GetCaptureProperties(this ICaptureGrab capture)
        {
            var settings = new CaptureConfig();
            settings.Resolution.Height = Convert.ToInt32(capture.GetCaptureProperty(CapProp.FrameHeight));
            settings.Resolution.Width = Convert.ToInt32(capture.GetCaptureProperty(CapProp.FrameWidth));
            settings.Framerate = Convert.ToInt32(capture.GetCaptureProperty(CapProp.Fps));
            settings.Monochrome = Convert.ToBoolean(capture.GetCaptureProperty(CapProp.Monochrome));
            return settings;
        }