/// <summary> /// 清除原来的事件和操作信息 /// </summary> public void clearPreMessage() { _inkCollector.SelectKeyFrames.Clear(); if (thumbPlayer != null) { _inkCanvas.Children.Remove(thumbPlayer.VideoPlayer); } _inkCollector._mainPage._thumbVideoPlayer.videoPlayer.Source = null; _inkCollector._mainPage._thumbVideoPlayer.Visibility = Visibility.Collapsed; if (preImage != null) { _inkCanvas.Children.Remove(preImage); } //清除注释框 if (_keyFrameAnnotation != null && keyFramesAnnotation != null) { _keyFrameAnnotation.Visibility = Visibility.Collapsed; //记录宽度和高度 //_keyFramesAnnotation.Width = this.Width; //_keyFramesAnnotation.Height = this.Height; foreach (int index in keyFramesAnnotation.relatedKeyFrameIndexes) { KeyValuePair <Stroke, KeyFramesAnnotation> currPair = (from KeyValuePair <Stroke, KeyFramesAnnotation> anno in _inkCollector.VideoSummarization.ShowKeyFrames[index].Annotations where anno.Value == keyFramesAnnotation select anno).First(); Stroke linkline = (Stroke)(currPair.Key); _inkCollector._mainPage._inkCanvas.Strokes.Remove(linkline); } _inkCollector._mainPage.LayoutRoot.Children.Remove(_keyFrameAnnotation); _keyFrameAnnotation = null; } }
void MoveTimer_Tick(object sender, EventArgs e) { if (_startPoint.X == 0 && _startPoint.Y == 0)// && _inkCollector.KeyFrameAnnotation.Visibility == Visibility.Collapsed) { moveTimerSecond += 1; if (moveTimerSecond >= 3 && currIndex != int.MinValue && currIndex < videoSummarization.ShowKeyFrames.Count && _inkCollector.IsShowUnbrokenKeyFrame) { if (preImage != null) { _inkCanvas.Children.Remove(preImage); } if (_keyFrameAnnotation != null) { _inkCollector._mainPage.LayoutRoot.Children.Remove(_keyFrameAnnotation); _keyFrameAnnotation = null; } left = videoSummarization.ShowKeyFrames[currIndex].Image.Margin.Left; // +videoSummarization.ShowKeyFrames[currIndex].Image.Width / 2 - 60; top = videoSummarization.ShowKeyFrames[currIndex].Image.Margin.Top; // +videoSummarization.ShowKeyFrames[currIndex].Image.Height / 2 - 40; left += inkCanvasSpiralSummarizationMargin.Left; top += inkCanvasSpiralSummarizationMargin.Top; if (_inkCollector.DefaultSummarizationNum == 1) { top += videoSummarization.InkCanvas.Margin.Top; } _inkCollector.SelectKeyFrames.Add(videoSummarization.KeyFrames[currIndex]); int videoTime = videoSummarization.ShowKeyFrames[currIndex].Time; //在关键帧上画圆,显示小视频 _inkCollector._mainPage._thumbVideoPlayer.Margin = new Thickness(left, top - 40, 0, 0); _inkCollector._mainPage._thumbVideoPlayer.Visibility = Visibility.Visible; _inkCollector._mainPage._thumbVideoPlayer.InitVideoPlayer(videoSummarization.ShowKeyFrames[currIndex].VideoName, videoTime, 5000, true); _inkCollector._mainPage._thumbVideoPlayer.videoPlayer.MouseLeftButtonUp += new MouseButtonEventHandler(thumbVideoPlayer_MouseLeftButtonUp); //显示关键帧注释 KeyFrame selectKeyFrame = videoSummarization.ShowKeyFrames[currIndex]; Dictionary <Stroke, KeyFramesAnnotation> s = selectKeyFrame.Annotations; if (s.Count > 0) { _keyFrameAnnotation = new KeyFrameAnnotation(); _keyFrameAnnotation.setInkCollector(_inkCollector); _keyFrameAnnotation.setKeyFramesAnnotation(keyFramesAnnotation, false); KeyValuePair <Stroke, KeyFramesAnnotation> currPair = (from KeyValuePair <Stroke, KeyFramesAnnotation> anno in selectKeyFrame.Annotations //where anno.Value == _keyFramesAnnotation select anno).First(); keyFramesAnnotation = (KeyFramesAnnotation)(currPair.Value); foreach (int index in keyFramesAnnotation.relatedKeyFrameIndexes) { currPair = (from KeyValuePair <Stroke, KeyFramesAnnotation> anno in videoSummarization.ShowKeyFrames[index].Annotations where anno.Value == keyFramesAnnotation select anno).First(); Stroke stroke = (Stroke)(currPair.Key); if (_inkCanvas.Strokes.IndexOf(stroke) == -1) { _inkCanvas.Strokes.Add(stroke); } } _keyFrameAnnotation.InkCanvasAnnotation.Strokes.Add(keyFramesAnnotation.Strokes); //显示关键帧注释 _keyFrameAnnotation.Width = keyFramesAnnotation.Width; _keyFrameAnnotation.Height = keyFramesAnnotation.Height; _keyFrameAnnotation.VerticalAlignment = VerticalAlignment.Top; if (videoSummarization.ShowKeyFrameCenterPoints[startIndex].X < videoSummarization.Center.X) { _keyFrameAnnotation.HorizontalAlignment = HorizontalAlignment.Left; } else { _keyFrameAnnotation.HorizontalAlignment = HorizontalAlignment.Right; } _keyFrameAnnotation.Visibility = Visibility.Visible; _inkCollector._mainPage.LayoutRoot.Children.Add(_keyFrameAnnotation); } moveTimerSecond = 0; } } }
public void VideoPlayTimer_Tick(object sender, EventArgs e) { int videoTimeNow = (int)VideoSummarizationControl.mediaPlayer.Position.TotalMilliseconds; //修改时间轴和播放时间 VideoSummarizationControl._timeBar.Value = videoTimeNow; //修改显示播放进度的值的textbox List <string> timeCurr = new List <string>(); timeCurr = ConvertClass.getInstance().MsToHMS(videoTimeNow); VideoSummarizationControl.VideoProgressText.Text = timeCurr[0] + ":" + timeCurr[1] + ":" + timeCurr[2] + "/" + timeTotalString; //显示超链接关键帧 foreach (KeyFrame keyFrame in _inkCollector.HyperLinkKeyFrames) { if (keyFrame.VideoName == videoSource && (int)(keyFrame.Time / 1000) == (int)(videoTimeNow / 1000)) { if (hyperLink != null) { VideoSummarizationControl.TableGrid.Children.Remove(hyperLink.Image); } hyperLink = keyFrame.HyperLink; VideoSummarizationControl.hyperLinkPlayer.Visibility = Visibility.Visible; VideoSummarizationTool.locateMediaPlayer(VideoSummarizationControl.hyperLinkPlayer, hyperLink); hyperLinkPlayTimer = new System.Windows.Forms.Timer(); hyperLinkPlayTimer.Interval = 8000; hyperLinkPlayTimer.Tick += new System.EventHandler(hyperLinkPlayTimer_Tick); hyperLinkPlayTimer.Start(); hyperLinkSpiralSummarization = keyFrame.HyperLinkSpiralSummarization; VideoSummarizationControl.hyperLinkPlayer.MouseLeftButtonUp += new MouseButtonEventHandler(hyperLinkPlayer_MouseLeftButtonUp); break; } } bool isHasAnnotation = false; bool isHasKeyFrame = false; foreach (KeyFrame keyFrame in videoSummarization.KeyFrames) { if ((int)(keyFrame.Time / 1000) == (int)(videoTimeNow / 1000)) { if (_inkCollector.DefaultSummarizationNum == 0 && _inkCollector.IsShowRedPoint) { //在螺旋摘要中修改螺旋线表明播放到当前帧了 int currIndex = videoSummarization.KeyFrames.IndexOf(keyFrame); if (currPlayKeyFrameStroke != null) { _inkCollector.VideoSummarization.InkCanvas.Strokes.Remove(currPlayKeyFrameStroke); } currPlayKeyFrameStroke = _inkCollector.VideoSummarization.AddPoint2Track(currIndex, Colors.Red, 8); } //显示草图注释 isHasKeyFrame = true; Dictionary <Stroke, KeyFramesAnnotation> s = keyFrame.Annotations; if (s.Count > 0) { KeyValuePair <Stroke, KeyFramesAnnotation> currPair; if (_keyFrameAnnotation != null && keyFramesAnnotation != null) { _keyFrameAnnotation.Visibility = Visibility.Collapsed; _inkCollector._mainPage.LayoutRoot.Children.Remove(_keyFrameAnnotation); _keyFrameAnnotation = null; foreach (int index in keyFramesAnnotation.relatedKeyFrameIndexes) { currPair = (from KeyValuePair <Stroke, KeyFramesAnnotation> anno in _inkCollector.VideoSummarization.ShowKeyFrames[index].Annotations where anno.Value == keyFramesAnnotation select anno).First(); Stroke linkline = (Stroke)(currPair.Key); _inkCollector._mainPage._inkCanvas.Strokes.Remove(linkline); } } _keyFrameAnnotation = new KeyFrameAnnotation(); currPair = (from KeyValuePair <Stroke, KeyFramesAnnotation> anno in keyFrame.Annotations //where anno.Value == _keyFramesAnnotation select anno).First(); keyFramesAnnotation = (KeyFramesAnnotation)(currPair.Value); int firstIndex = 0; int count = 0; foreach (int index in keyFramesAnnotation.relatedKeyFrameIndexes) { if (count == 0) { firstIndex = index; } count++; currPair = (from KeyValuePair <Stroke, KeyFramesAnnotation> anno in videoSummarization.ShowKeyFrames[index].Annotations where anno.Value == keyFramesAnnotation select anno).First(); Stroke stroke = (Stroke)(currPair.Key); if (_inkCanvas.Strokes.IndexOf(stroke) == -1) { _inkCanvas.Strokes.Add(stroke); } } _keyFrameAnnotation.InkCanvasAnnotation.Strokes.Add(keyFramesAnnotation.Strokes); //显示关键帧注释 _keyFrameAnnotation.Width = keyFramesAnnotation.Width; _keyFrameAnnotation.Height = keyFramesAnnotation.Height; _keyFrameAnnotation.VerticalAlignment = VerticalAlignment.Top; if (videoSummarization.ShowKeyFrameCenterPoints[firstIndex].X < videoSummarization.Center.X) { _keyFrameAnnotation.HorizontalAlignment = HorizontalAlignment.Left; } else { _keyFrameAnnotation.HorizontalAlignment = HorizontalAlignment.Right; } _keyFrameAnnotation.Visibility = Visibility.Visible; _inkCollector._mainPage.LayoutRoot.Children.Add(_keyFrameAnnotation); //VideoSummarizationControl.BtnSpiralScreenBack.Visibility = Visibility.Collapsed; //VideoSummarizationControl.BtnSpiralScreen.Visibility = Visibility.Collapsed; isHasAnnotation = true; } break; } } if (isHasKeyFrame && !isHasAnnotation && _inkCollector.Mode != InkMode.AddKeyFrameAnnotationDouble) { KeyValuePair <Stroke, KeyFramesAnnotation> currPair; if (_keyFrameAnnotation != null && keyFramesAnnotation != null) { _keyFrameAnnotation.Visibility = Visibility.Collapsed; foreach (int index in keyFramesAnnotation.relatedKeyFrameIndexes) { currPair = (from KeyValuePair <Stroke, KeyFramesAnnotation> anno in _inkCollector.VideoSummarization.ShowKeyFrames[index].Annotations where anno.Value == keyFramesAnnotation select anno).First(); Stroke linkline = (Stroke)(currPair.Key); _inkCollector._mainPage._inkCanvas.Strokes.Remove(linkline); } } } }
/// <summary> /// 方向和笔序识别结果匹配和处理 /// </summary> /// <param name="args"></param> void gesture_GestureMatchEvent(MouseGestureEventArgs args) { //记录操作事件与持续时间 recordOperateEvent(args.Present); switch (args.Present) { case "keyFrameAnnotation": if (startIndex != int.MinValue && startIndex == endIndex && _inkCollector.IsShowUnbrokenKeyFrame) { _keyFrameAnnotation = new KeyFrameAnnotation(); KeyFrame selectKeyFrame = videoSummarization.ShowKeyFrames[startIndex]; _inkCollector.SelectKeyFrames.Add(videoSummarization.ShowKeyFrames[startIndex]); Dictionary <Stroke, KeyFramesAnnotation> s = selectKeyFrame.Annotations; //在已经有注释的情况下显示已有的注释 if (selectKeyFrame.Annotations.Count > 0) { KeyValuePair <Stroke, KeyFramesAnnotation> currPair = (from KeyValuePair <Stroke, KeyFramesAnnotation> anno in selectKeyFrame.Annotations //where anno.Value == _keyFramesAnnotation select anno).First(); keyFramesAnnotation = (KeyFramesAnnotation)(currPair.Value); foreach (int index in keyFramesAnnotation.relatedKeyFrameIndexes) { currPair = (from KeyValuePair <Stroke, KeyFramesAnnotation> anno in videoSummarization.ShowKeyFrames[index].Annotations where anno.Value == keyFramesAnnotation select anno).First(); Stroke stroke = (Stroke)(currPair.Key); _inkCanvas.Strokes.Add(stroke); } _keyFrameAnnotation.InkCanvasAnnotation.Strokes.Add(keyFramesAnnotation.Strokes); } else { keyFramesAnnotation = new KeyFramesAnnotation(); } _inkCollector.KeyFramesAnnotation = keyFramesAnnotation; _inkCollector.KeyFrameAnnotation = _keyFrameAnnotation; _keyFrameAnnotation.setInkCollector(_inkCollector); _keyFrameAnnotation.setKeyFramesAnnotation(keyFramesAnnotation, true); //显示关键帧注释 _keyFrameAnnotation.Width = keyFramesAnnotation.Width; _keyFrameAnnotation.Height = keyFramesAnnotation.Height; _keyFrameAnnotation.VerticalAlignment = VerticalAlignment.Top; Stroke linkLine; if (videoSummarization.ShowKeyFrameCenterPoints[startIndex].X < videoSummarization.Center.X) { _keyFrameAnnotation.HorizontalAlignment = HorizontalAlignment.Left; if (selectKeyFrame.Annotations.Count == 0) { //画关键帧到注释框的连线 linkLine = InkTool.getInstance().DrawLine(videoSummarization.ShowKeyFrameCenterPoints[startIndex].X + inkCanvasSpiralSummarizationMargin.Left, videoSummarization.ShowKeyFrameCenterPoints[startIndex].Y + inkCanvasSpiralSummarizationMargin.Top, _keyFrameAnnotation.Margin.Left + _keyFrameAnnotation.Width / 2, _keyFrameAnnotation.Margin.Top + _keyFrameAnnotation.Height / 2, _inkCanvas, Color.FromArgb(180, 0, 255, 0)); selectKeyFrame.Annotations.Add(linkLine, keyFramesAnnotation); keyFramesAnnotation.relatedKeyFrameIndexes.Add(startIndex); MoveTimer.Stop(); } } else { _keyFrameAnnotation.HorizontalAlignment = HorizontalAlignment.Right; if (selectKeyFrame.Annotations.Count == 0) { linkLine = InkTool.getInstance().DrawLine(videoSummarization.ShowKeyFrameCenterPoints[startIndex].X + inkCanvasSpiralSummarizationMargin.Left, videoSummarization.ShowKeyFrameCenterPoints[startIndex].Y + inkCanvasSpiralSummarizationMargin.Top, _inkCanvas.ActualWidth - _keyFrameAnnotation.Width / 2, _keyFrameAnnotation.Margin.Top + _keyFrameAnnotation.Height / 2, _inkCanvas, Color.FromArgb(180, 0, 255, 0)); selectKeyFrame.Annotations.Add(linkLine, keyFramesAnnotation); keyFramesAnnotation.relatedKeyFrameIndexes.Add(startIndex); MoveTimer.Stop(); } } _keyFrameAnnotation.Visibility = Visibility.Visible; _inkCollector._mainPage.LayoutRoot.Children.Add(_keyFrameAnnotation); _inkCollector.Mode = InkMode.AddKeyFrameAnnotation; } else { //VideoSummarizationControl.TableGrid.ColumnDefinitions[0].Width = new GridLength(VideoSummarizationControl.TableGrid.ActualWidth * 0.25); } break; case "SpiralFullScreen": //VideoSummarizationControl.TableGrid.ColumnDefinitions[0].Width = new GridLength(0); break; default: //Console.WriteLine("default"); break; } }