Module: MobyUtil
- Defined in:
- lib/tdriver/util/xml/xml.rb,
lib/tdriver/util/xml/text.rb,
lib/tdriver/util/xml/error.rb,
lib/tdriver/util/common/gem.rb,
lib/tdriver/util/common/file.rb,
lib/tdriver/util/xml/builder.rb,
lib/tdriver/util/xml/comment.rb,
lib/tdriver/util/xml/element.rb,
lib/tdriver/util/xml/nodeset.rb,
lib/tdriver/util/common/array.rb,
lib/tdriver/util/common/error.rb,
lib/tdriver/util/plugin/error.rb,
lib/tdriver/util/video/camera.rb,
lib/tdriver/util/xml/document.rb,
lib/tdriver/util/xml/nil_node.rb,
lib/tdriver/util/common/kernel.rb,
lib/tdriver/util/common/string.rb,
lib/tdriver/util/logger/logger.rb,
lib/tdriver/util/xml/attribute.rb,
lib/tdriver/util/database/error.rb,
lib/tdriver/util/plugin/service.rb,
lib/tdriver/util/database/access.rb,
lib/tdriver/util/hooking/hooking.rb,
lib/tdriver/util/parameter/error.rb,
lib/tdriver/util/plugin/abstract.rb,
lib/tdriver/util/user_data/error.rb,
lib/tdriver/util/xml/abstraction.rb,
lib/tdriver/util/common/retryable.rb,
lib/tdriver/util/recorder/recorder.rb,
lib/tdriver/util/recorder/scripter.rb,
lib/tdriver/util/video/video_utils.rb,
lib/tdriver/util/common/environment.rb,
lib/tdriver/util/localisation/error.rb,
lib/tdriver/util/video/camera_linux.rb,
lib/tdriver/util/database/connection.rb,
lib/tdriver/util/operator_data/error.rb,
lib/tdriver/util/parameter/parameter.rb,
lib/tdriver/util/user_data/user_data.rb,
lib/tdriver/util/video/camera_windows.rb,
lib/tdriver/util/statistics/statistics.rb,
lib/tdriver/util/filters/attribute_filter.rb,
lib/tdriver/util/localisation/localisation.rb,
lib/tdriver/util/xml/parsers/libxml/libxml.rb,
lib/tdriver/util/xml/parsers/nokogiri/node.rb,
lib/tdriver/util/xml/parsers/nokogiri/text.rb,
lib/tdriver/util/operator_data/operator_data.rb,
lib/tdriver/util/xml/parsers/nokogiri/builder.rb,
lib/tdriver/util/xml/parsers/nokogiri/comment.rb,
lib/tdriver/util/xml/parsers/nokogiri/element.rb,
lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb,
lib/tdriver/util/xml/parsers/nokogiri/document.rb,
lib/tdriver/util/xml/parsers/nokogiri/attribute.rb,
lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb
Overview
Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. Contact: Nokia Corporation ([email protected])
This file is part of Testability Driver.
If you have questions regarding the use of this file, please contact Nokia at [email protected] .
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation and appearing in the file LICENSE.LGPL included in the packaging of this file.
Defined Under Namespace
Modules: XML Classes: ArrayHelper, CustomError, DBAccess, DBConnection, DbTypeNotDefinedError, DbTypeNotSupportedError, DynamicAttributeFilter, EmptyFilenameError, EnvironmentHelper, FileHelper, FileNotFoundError, GemHelper, Hooking, KernelHelper, LanguageNotFoundError, Localisation, Logger, LogicalNameNotFoundError, OperatorData, OperatorDataColumnNotFoundError, OperatorDataNotFoundError, Parameter, ParameterFileParseError, ParameterHash, ParameterNotFoundError, ParameterUserAPI, ParameterXmlParseError, Plugin, PluginError, PluginService, Recorder, Retryable, Scripter, SqlConnectError, SqlError, Stats, StringHelper, TDriverCam, TDriverLinuxCam, TDriverWinCam, TableNotFoundError, TemplateNotFoundError, TemplatesFileNotLoaded, UnexpectedVariableTypeError, UserData, UserDataColumnNotFoundError, UserDataNotFoundError, VerifyBlock
Class Method Summary collapse
-
.video_alive?(in_target_video, in_fps = 1, in_image_treshold = 4, in_video_treshold = 35, in_verbose = false) ⇒ Boolean
Checks if the target video contains enough activity to be considered active or static.
Class Method Details
.video_alive?(in_target_video, in_fps = 1, in_image_treshold = 4, in_video_treshold = 35, in_verbose = false) ⇒ Boolean
Checks if the target video contains enough activity to be considered active or static.
params
in_target_video: String, Name and path of video file to analyze in_fps: (optional) Numeric, frames to be analyzed per second in_image_treshold: (optional) Numeric, minimum change between two frames for them to be considered different in_video_treshold: (optional) Numeric, Minimum percentage of frames with changes for the video to be considered alive. in_verbose: (optional) Boolean, True for verbose output including target video statistics
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/tdriver/util/video/video_utils.rb', line 32 def self.video_alive?( in_target_video, in_fps = 1, in_image_treshold = 4, in_video_treshold = 35, in_verbose = false ) puts "Arguments fps: " << in_fps.inspect << " frame: " << in_image_treshold.inspect << " video: " << in_video_treshold.inspect if in_verbose in_change = in_image_treshold / 100.0 alive_temp_folder = "temp_target_alive" require 'RMagick' raise ArgumentError.new( "The FPS argument must be an Interger or a Float, it was a #{ in_fps.class }." ) unless in_fps.kind_of? Numeric raise ArgumentError.new( "The frame treshold argument must be an Interger or a Float, it was a #{ in_image_treshold.class }." ) unless in_image_treshold.kind_of? Numeric raise ArgumentError.new( "The video treshold argument must be an Interger or a Float, it was a #{ in_video_treshold.class }." ) unless in_video_treshold.kind_of? Numeric ts = Time.now if in_verbose begin FileUtils.remove_dir alive_temp_folder rescue # failed to remove dir, do nothing end begin FileUtils.mkdir_p alive_temp_folder rescue end begin File.delete 'video_split.log' if File.exist? 'video_split.log' rescue end if in_verbose system('ffmpeg -v 0 -i '+in_target_video.to_s+' -y -f image2 -r '+in_fps.to_s+' '+alive_temp_folder+'/frame-%05d.png') else system('ffmpeg 2>video_split.log -v 0 -i '+in_target_video.to_s+' -y -f image2 -r '+in_fps.to_s+' '+alive_temp_folder+'/frame-%05d.png') end puts "Video processing duration: " << (Time.now - ts).to_s if in_verbose t_start = Time.now im_files = Dir.glob( alive_temp_folder + '/frame-*.png' ) raise RuntimeError.new( "No video frames found for analysis." ) if im_files.size == 0 d_max = 0.0 d_min = 1.0 d_sum = 0.0 dif_count = 0 pre_obj = Magick::ImageList.new(im_files[0]) (im_files.size-1).times do | im_index | im_file = Magick::ImageList.new(im_files[ im_index ]) pre_file = pre_obj dif = pre_file.compare_channel(im_file, Magick::RootMeanSquaredErrorMetric)[1] if in_verbose d_min = dif unless dif >= d_min d_max = dif unless dif <= d_max d_sum += dif end dif_count += 1 if dif > in_change puts "Processing image: " << im_file.to_s << " I: " << (im_index+1).to_s << " C: " << dif.to_s if in_verbose pre_obj = im_file end if in_verbose time_now = Time.now puts "Max difference: " << d_max.to_s << "\nMin difference: " << d_min.to_s << "\n" puts "Mean difference: " << (d_sum/im_files.size).to_s unless im_files.size == 0 puts "Count of images exceeding difference tolerance: " << dif_count.to_s puts "Fraction of images exceeding difference tolerance: " << (dif_count.to_f/im_files.size).to_s unless im_files.size == 0 puts "Analysis duration: " << (time_now - t_start).to_s puts "Total duration: " << (time_now - ts).to_s end begin FileUtils.remove_dir alive_temp_folder rescue end begin File.delete 'video_split.log' if File.exist? 'video_split.log' rescue end # Check if enough frames had changes return (dif_count.to_f/im_files.size)*100 >= in_video_treshold end |