/// <summary> /// Checks the video for matches. /// </summary> /// <param name="videoPath">The video path.</param> /// <param name="desiredTag">The desired tag to look for in the video.</param> /// <param name="startingPoint">The starting point of the search (in seconds).</param> /// <returns> Image data object </returns> public static async Task <FrameDto> CheckVideoForMatches (string videoPath, string desiredTag, double startingPoint = 0) { VideoFileReader reader = new VideoFileReader(); reader.Open(videoPath); double rate = reader.FrameRate.ToDouble(); for (int i = 0; i < reader.FrameCount; i++) { try { byte[] frame = ImageManager.ToBytes(reader.ReadVideoFrame()); double current_seconds = i * 1.0 / rate; if (i % rate != 0 || startingPoint > current_seconds) // for efficiency: only do analysis every 1 second (or every N=rate frames) { continue; } JToken analysis = await ComputerVisionManager.AnalyzeImage(frame); if (ImageManager.CheckMatch(desiredTag, analysis)) { reader.Close(); return(new FrameDto() { Analysis = analysis, OccurenceTime = TimeSpan.FromSeconds(current_seconds), DesiredTag = desiredTag }); } } catch (Exception) { continue; } } reader.Close(); return(null); }
static void Main(string[] args) { ComputerVisionManager manager = new ComputerVisionManager(); IResult result = manager.AnalyzeImage("{subscription key}", "http://static.cnbetacdn.com/thumb/article/2017/0131/9a0adc9b1362043.jpg_600x600.jpg", //"https://imgsa.baidu.com/baike/c0%3Dbaike116%2C5%2C5%2C116%2C38/sign=9047a0f3af1ea8d39e2f7c56f6635b2b/c2fdfc039245d6887782a5ecadc27d1ed31b24f1.jpg", new VisualFeature[] { VisualFeature.Adult, VisualFeature.Categories, VisualFeature.Color, VisualFeature.Description, VisualFeature.Faces, VisualFeature.ImageType, VisualFeature.Tags }, string.Empty, Language.en); }