Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            youtubeLink = new YoutubeLink();

            VideoLink.SetBinding(TextBox.TextProperty, new Binding("link")
            {
                Source = youtubeLink,
                Mode   = BindingMode.OneWayToSource,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            });

            VideoTitle.SetBinding(Label.ContentProperty, new Binding("title")
            {
                Source = youtubeLink,
                Mode   = BindingMode.OneWay
            });

            VideoProgress.SetBinding(ProgressBar.ValueProperty, new Binding("progress")
            {
                Source = youtubeLink,
                Mode   = BindingMode.OneWay
            });

            VideoImage.SetBinding(Image.SourceProperty, new Binding("image")
            {
                Source = youtubeLink,
                Mode   = BindingMode.OneWay
            });
        }
Ejemplo n.º 2
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create([Bind("id,title,description")] Post post)
        {
            if (ModelState.IsValid)
            {
                Owner user_Session = um.GetUser_Session(Request);
                post.date_created = DateTime.Now;
                post.owner        = user_Session;
                post.modify_date  = DateTime.Now;
                var path    = _env.WebRootPath;
                var uploads = Path.Combine(path, "img");
                List <VideoImage> VideoImages = new List <VideoImage>();
                var files = HttpContext.Request.Form.Files;
                foreach (IFormFile file in files)
                {
                    string extension = System.IO.Path.GetExtension(file.FileName);
                    string _id       = ObjectId.GenerateNewId().ToString();
                    await save_fileAsync(_id + extension, uploads, file);

                    VideoImage videoImage = new VideoImage
                    {
                        _id  = _id,
                        type = extension,
                        link = "/img/" + _id + extension
                    };
                    VideoImages.Add(videoImage);
                }
                post.video_image = VideoImages;
                await pm.insertPostAsync(post);

                return(Ok(new { Message = "Post created sucessfully" }));
            }
            return(BadRequest(new { Message = "Please fill all fields" }));
        }
Ejemplo n.º 3
0
        public async Task <UploadImagesForVideoResponseMessage> Handle(UploadImagesForVideoRequestMessage request, CancellationToken cancellationToken)
        {
            var validationResult = _validator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(new UploadImagesForVideoResponseMessage(validationResult));
            }

            var video = await _repository.GetByIdAsync <Video>(request.VideoId);

            if (video == null)
            {
                //remove that after testing
                validationResult.Errors.Add(new FluentValidation.Results.ValidationFailure("video", "not found 404"));
                return(new UploadImagesForVideoResponseMessage(validationResult));
            }

            List <string> imageUris = new List <string>();

            foreach (var data in request.FilesData)
            {
                var uri = await _imageStorage.Upload(data);

                var image = new VideoImage(Guid.NewGuid().ToString(), uri);

                imageUris.Add(uri);

                video.RegisterImage(image);
                await _repository.UpdateAsync <Video>(video);
            }

            return(new UploadImagesForVideoResponseMessage(validationResult, imageUris));
        }
Ejemplo n.º 4
0
 public XnaVideo(string filename, XnaMedia.VideoPlayer player, XnaDevice graphicsDevice,
                 SoundDevice soundDevice)
     : base(filename, soundDevice)
 {
     this.player         = player;
     this.graphicsDevice = graphicsDevice;
     image = new VideoImage(graphicsDevice);
 }
Ejemplo n.º 5
0
        public string GetvideoURLByImage(int image_id)
        {
            VideoImage img = DAManager.VideoImagesRepository.Get(i => i.ImageId == image_id, null, "Video").FirstOrDefault();

            if (img == null)
            {
                return("");
            }
            else
            {
                return(img.Video.URL);
            }
        }
Ejemplo n.º 6
0
        public MediaView(ViewModel.PinballFrontEndViewModel viewModel)
        {
            //this.DataContext = this;
            InitializeComponent();
            this.viewModel   = viewModel;
            this.DataContext = this.viewModel;

            this.viewModel.TableChanged += ViewModel_TableChanged;

            ///////////////////////////////////////////////////////////////////////////////////////////////////
            // SETUP Delay Timers
            ///////////////////////////////////////////////////////////////////////////////////////////////////

            //Start Video Update Timer
            vidTimer          = new System.Timers.Timer(500);
            vidTimer.Elapsed += VidTimer_Elapsed;

            //CurrentSource = new Uri(".");
            vidTimer.AutoReset = false;
            vidTimer.Start();

            showTimer           = new System.Timers.Timer(500);
            showTimer.Elapsed  += ShowTimer_Elapsed;
            showTimer.AutoReset = false;
            showTimer.Start();



            // SETUP VLC LIBRARY

            //Create Video Source Provider
            sourceProvider = new VlcVideoSourceProvider(this.Dispatcher);
            sourceProvider.CreatePlayer(Model.VlcGlobal.GetVlcLibrary());
            sourceProvider.MediaPlayer.Log     += ((a, b) => { }); //Do nothing with log
            sourceProvider.MediaPlayer.Playing += MediaPlayer_Playing;

            //Bind source provider to image
            VideoImage.SetBinding(Image.SourceProperty, new Binding(nameof(VlcVideoSourceProvider.VideoSource))
            {
                Source = sourceProvider
            });
        }
Ejemplo n.º 7
0
		/// <summary> 
		/// Создаёт объект <see cref="FaceDetector"/>
		/// </summary>
		/// <param name="videoImage"> Изображение. </param>
		public FaceDetector(VideoImage videoImage)
		{
			Classifier = new CascadeClassifier(
				Path.Combine(
					Directory.GetCurrentDirectory(),
					"Samples",
					"haarcascade_frontalface_default.xml"));

			//creating bitmap
			System.Drawing.Bitmap bitmap = videoImage.Matrix.CreateBitmap();

			//converting System.Drawing.Bitmap -> OpenCVSharp.CPlusPlus.Mat
			if(bitmap != null) { 
				Mat mat = BitmapConverter.ToMat(bitmap);
				InputMatrix = mat;
				OutputMatrix = InputMatrix.Clone();
			}

			FacesRepository = new List<Mat>();
		}
Ejemplo n.º 8
0
        public int ReadImage(long posToSeek, out VideoImage vi)
        {
            NativeMethods.WWMFVideoFormat vf = new NativeMethods.WWMFVideoFormat();
            vi = new VideoImage();

            int imgBytes = 3840 * 2160 * 4;
            var img      = new byte[imgBytes];

            int hr = NativeMethods.WWMFVReaderIFReadImage(mInstanceId, posToSeek, img, ref imgBytes, ref vf);

            if (0 <= hr)
            {
                vi.w         = vf.aperture.w;
                vi.h         = vf.aperture.h;
                vi.img       = img;
                vi.duration  = vf.duration;
                vi.timeStamp = vf.timeStamp;
            }

            //SaveImgToFile(vi, string.Format("{0}_{1}.data", mInstanceId, vi.timeStamp));

            return(hr);
        }
Ejemplo n.º 9
0
 private static void SaveImgToFile(VideoImage vi, string path)
 {
     using (var bw = new BinaryWriter(File.Open(path, FileMode.Create, FileAccess.Write))) {
         bw.Write(vi.img, 0, vi.img.Length);
     }
 }
Ejemplo n.º 10
0
        private void runMission(MissionSpec mission)
        {
            string            recordPath = "none";
            MissionRecordSpec missionRecord;

            if (string.IsNullOrEmpty(Settings.Default.OutputDir))
            {
                missionRecord = new MissionRecordSpec();
            }
            else
            {
                recordPath    = Path.Combine(Settings.Default.OutputDir, Guid.NewGuid() + ".tar.gz");
                missionRecord = new MissionRecordSpec(recordPath);
                if (Settings.Default.RecordObservations)
                {
                    missionRecord.recordObservations();
                }

                if (Settings.Default.RecordRewards)
                {
                    missionRecord.recordRewards();
                }

                if (Settings.Default.RecordCommands)
                {
                    missionRecord.recordCommands();
                }

                if (Settings.Default.RecordMP4)
                {
                    missionRecord.recordMP4(Settings.Default.MP4FPS, (long)(Settings.Default.BitRate * 1024));
                }
            }

            using (AgentHost agentHost = new AgentHost())
            {
                ClientPool clientPool = new ClientPool();
                clientPool.add(new ClientInfo(Settings.Default.ClientIP, Settings.Default.ClientPort));

                try
                {
                    agentHost.startMission(mission, clientPool, missionRecord, 0, "hac");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Starting Mission", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                Dispatcher.Invoke(() =>
                {
                    Activate();
                    VideoImage.Focus();
                    startB.Content = "Set";
                    Title          = Settings.Default.Title + " : Waiting for mission start";
                    if (_recordWindow != null && _recordWindow.IsVisible)
                    {
                        _recordWindow.RecordPath = recordPath;
                    }
                });

                _isInSession = true;
                try
                {
                    WorldState worldState;
                    // wait for mission to start
                    do
                    {
                        Thread.Sleep(100);
                        worldState = agentHost.getWorldState();

                        if (worldState.errors.Any())
                        {
                            StringBuilder errors = new StringBuilder();
                            foreach (TimestampedString error in worldState.errors)
                            {
                                errors.AppendLine(error.text);
                            }

                            MessageBox.Show(errors.ToString(), "Error during mission initialization", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                    }while (!worldState.is_mission_running && !_stopMission);

                    if (_stopMission)
                    {
                        return;
                    }

                    DateTime missionStartTime = DateTime.UtcNow;
                    _timeRemaining = _missionDuration;

                    Dispatcher.Invoke(() =>
                    {
                        startB.Content = "Go!";
                        Title          = Settings.Default.Title + " : Recording";
                    });

                    // run mission
                    TimeSpan loopTime = TimeSpan.FromSeconds(1.0 / 20);

                    _pendingCommandsMutex.Wait();
                    try
                    {
                        _pendingCommandQueue = new Queue <Tuple <string, float> >();
                    }
                    finally
                    {
                        _pendingCommandsMutex.Release();
                    }

                    _pendingMessagesMutex.Wait();
                    try
                    {
                        _pendingMessages = new Queue <string>();
                    }
                    finally
                    {
                        _pendingMessagesMutex.Release();
                    }

                    bool      failure   = false;
                    Stopwatch loopTimer = new Stopwatch();
                    do
                    {
                        loopTimer.Reset();
                        loopTimer.Start();

                        worldState = agentHost.getWorldState();

                        TimestampedVideoFrame frame = worldState.video_frames.FirstOrDefault();

                        if (frame != null)
                        {
                            if (_missionDuration != TimeSpan.Zero)
                            {
                                TimeSpan elapsed = frame.timestamp - missionStartTime;
                                _timeRemaining = _missionDuration - elapsed;
                            }

                            _pixelsMutex.Wait();
                            try
                            {
                                if (_pixels == null || _pixels.Length != frame.pixels.Count)
                                {
                                    _pixels = new byte[frame.pixels.Count];
                                    Dispatcher.Invoke(() =>
                                    {
                                        if (_bitmap.Width != frame.width || _bitmap.Height != frame.height)
                                        {
                                            _bitmap           = new WriteableBitmap(frame.width, frame.height, 72, 72, PixelFormats.Rgb24, null);
                                            VideoImage.Source = _bitmap;
                                            if (_recordWindow != null && _recordWindow.IsVisible)
                                            {
                                                _recordWindow.FrameSource = _bitmap;
                                            }
                                        }
                                    });
                                }

                                frame.pixels.CopyTo(_pixels);
                            }
                            finally
                            {
                                _pixelsMutex.Release();
                            }
                        }

                        _pendingMessagesMutex.Wait();
                        try
                        {
                            foreach (var reward in worldState.rewards)
                            {
                                _score += reward.getValue();
                                if (reward.getValue() < 0)
                                {
                                    failure = true;
                                }

                                _pendingMessages.Enqueue(string.Format("{0}> score {1}", reward.timestamp.ToString("hh:mm:ss.fff"), reward.getValue()));
                            }

                            _score = Math.Max(_score, 0);
                            _score = Math.Min(_score, 99999);

                            foreach (var observation in worldState.observations)
                            {
                                int posStart = observation.text.IndexOf("\"XPos\"");
                                if (posStart < 0)
                                {
                                    continue;
                                }

                                int posEnd = observation.text.IndexOf("\"ZPos\"");
                                posEnd = observation.text.IndexOf(',', posEnd);

                                string   posSegment = observation.text.Substring(posStart, posEnd - posStart);
                                string[] pos        = posSegment.Split(',');
                                float    x          = Convert.ToSingle(pos[0].Split(':')[1]);
                                float    y          = Convert.ToSingle(pos[1].Split(':')[1]);
                                float    z          = Convert.ToSingle(pos[2].Split(':')[1]);

                                _pendingMessages.Enqueue(string.Format("{0}> (x={1:0.00}, y={2:0.00}, z={3:0.00})", observation.timestamp.ToString("hh:mm:ss.fff"), x, y, z));
                            }
                        }
                        finally
                        {
                            _pendingMessagesMutex.Release();
                        }

                        CheckGamepad(agentHost);

                        _pendingCommandsMutex.Wait();
                        try
                        {
                            while (_pendingCommandQueue.Any())
                            {
                                var command = _pendingCommandQueue.Dequeue();
                                CheckAndSend(agentHost, command.Item1, command.Item2);
                            }
                        }
                        finally
                        {
                            _pendingCommandsMutex.Release();
                        }

                        loopTimer.Stop();
                        if (loopTimer.Elapsed < loopTime)
                        {
                            Thread.Sleep(loopTime - loopTimer.Elapsed);
                        }
                    } while (worldState.is_mission_running && !_stopMission);

                    if (_stopMission)
                    {
                        return;
                    }

                    if (!failure)
                    {
                        _score += _timeRemaining.TotalSeconds * 100;
                    }

                    _missionSuccess = !failure;

                    _pendingCommandsMutex.Wait();
                    try
                    {
                        _pendingCommandQueue = null;
                    }
                    finally
                    {
                        _pendingCommandsMutex.Release();
                    }

                    Dispatcher.Invoke(() =>
                    {
                        Title = Settings.Default.Title + " : Ready";
                        UpdateDisplayedMessages();
                        UpdateDisplayedReward();
                    });

                    _resetVerb = null;

                    var keys = _continuousCommandState.Keys.ToList();
                    foreach (var verb in keys)
                    {
                        _continuousCommandState[verb] = 0;
                    }

                    keys = _discreteCommandState.Keys.ToList();
                    foreach (var verb in keys)
                    {
                        _discreteCommandState[verb] = false;
                    }

                    if (worldState.errors.Any())
                    {
                        StringBuilder errors = new StringBuilder();
                        foreach (TimestampedString error in worldState.errors)
                        {
                            errors.AppendLine(error.text);
                        }

                        MessageBox.Show(errors.ToString(), "Error during mission initialization", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error during mission", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                finally
                {
                    _isInSession = false;
                }
            }
        }