class Object

Public Instance Methods

compact_intevals(intervals) click to toggle source

Sorts the given intervals and joins overlapping ones to get a more compact representation @param [Array<Array<Time,Time>>] intervals time intervals @return [Array<Array<Time,Time>>] sorted and joined intervals

# File lib/log_tools/sel_copy.rb, line 49
def compact_intevals(intervals)
    #sort time intervals
    intervals = intervals.sort do |x,y|
                    x.first <=> y.first
                end

    #remove overlapping parts
    intervals.each_with_index do |interval,index|
        next unless interval
        (index+1).upto(intervals.size-1) do |i|
            if intervals[i].first < interval.last
                interval[1] = intervals[i].last
                intervals[i] = nil
            else
                break
            end
        end
    end
    intervals.delete_if do |interval| 
        interval == nil
    end
    intervals
end
from_mat(mat) click to toggle source
# File examples/helpers/frame2cv.rb, line 66
def from_mat(mat)
    if(mat.type == OpenCV::Cv::CV_8UC1)
        self.frame_mode = :MODE_GRAYSCALE
        self.pixel_size = 1
        self.row_size = mat.cols
        self.frame_status = :STATUS_VALID
        self.data_depth = 8
    elsif(mat.type == OpenCV::Cv::CV_8UC3)
        self.frame_mode = :MODE_RGB
        self.pixel_size = 3
        self.row_size = mat.cols*3
        self.frame_status = :STATUS_VALID
        self.data_depth = 8
    else
        raise "Unsupported mat type"
    end
    self.size.height = mat.rows
    self.size.width = mat.cols
    self.time = Time.now
    self.image.raw_memcpy(mat.data.address,mat.total*self.pixel_size)
end
mock_logfile(path, should_open) click to toggle source
# File test/test_post_processing.rb, line 10
def mock_logfile(path, should_open)
    file_paths << path
    if should_open
        mock = flexmock("mocked logfile at #{path}")
        flexmock(Pocolog::Logfiles).should_receive(:open).with(path).and_return(mock)
        streams = Array.new
        mock.should_receive(:streams).and_return { streams }
        mock.should_receive(:each_stream).and_return { streams }
        mock
    else
        flexmock(Pocolog::Logfiles).should_receive(:open).with(path).never
    end
end
mock_stream(logfile, stream_name, stream_type) click to toggle source
# File test/test_post_processing.rb, line 24
def mock_stream(logfile, stream_name, stream_type)
    stream = flexmock("mocked stream #{stream_name}:#{stream_type}", name: stream_name, type: flexmock(name: stream_type))
    logfile.streams << stream
    stream
end
region(min, max) click to toggle source
# File test/test_post_processing.rb, line 135
def region(min, max)
    LogTools::PostProcessing::Region.new(min, max)
end
selective_copy(reference_stream_name,folder,new_file_name,black_list = Array.new) click to toggle source

Copies all log samples lying insight a log interval of the reference stream to the new log file

@param [String] reference_stream_name the name of the reference stream @param [String] folder the path to the folder containing all log files @param [String] new_file_name path of the new log file @param [Array] black_list list of stream names which shall be ignored

# File lib/log_tools/sel_copy.rb, line 11
def selective_copy(reference_stream_name,folder,new_file_name,black_list = Array.new)
    folder = File.expand_path(folder)
    all_files = Dir.enum_for(:glob, File.join(folder, '*.*.log'))

    intervals = Array.new
    streams = Array.new
    logfiles = all_files.map do |file|
        file = Pocolog::Logfiles.new(File.open(file))
        file.streams.each do |stream|
            next if black_list.include?(stream.name)
            intervals << stream.time_interval if stream.name == reference_stream_name
            streams << stream
        end
        file
    end
    intervals = compact_intevals(intervals)

    #copy all time intervals matching the reference_stream
    output = Pocolog::Logfiles.new(Typelib::Registry.new)
    output.new_file(new_file_name)
    new_streams = Hash.new
    intervals.each do |interval|
        puts "interval: #{interval.first} / #{interval.last}"
        streams.each do |stream|
            if stream.samples?(interval.first,interval.last)
                puts "  #{stream.name} copy samples" 
                new_streams[stream.name] ||= output.stream(stream.name,stream.type,true)
                stream.copy_to(interval.first,interval.last,new_streams[stream.name])
            end
        end
    end
    output.close
end
to_file(filename) click to toggle source
# File examples/helpers/frame2cv.rb, line 13
def to_file(filename)
    OpenCV::Cv::imwrite(self.to_mat,filename)
end
to_mat() click to toggle source
# File examples/helpers/frame2cv.rb, line 17
def to_mat
    channels = if self.frame_mode == :MODE_UNDEFINED
                   0
               elsif(self.frame_mode == :MODE_BAYER)
                   1
               elsif(self.frame_mode == :MODE_BAYER_RGGB)
                   1
               elsif(self.frame_mode == :MODE_BAYER_BGGR)
                   1
               elsif(self.frame_mode == :MODE_BAYER_GBRG)
                   1
               elsif(self.frame_mode == :MODE_BAYER_GRBG)
                   1
               elsif(self.frame_mode == :MODE_GRAYSCALE)
                   1
               elsif(self.frame_mode == :MODE_UYVY)
                   1
               elsif(self.frame_mode == :MODE_RGB)
                   3
               elsif(self.frame_mode == :MODE_BGR)
                   3
               elsif(self.frame_mode == :MODE_RGB32)
                   4
               else
                   raise "Unsupported frame_mode #{self.frame_mode}";
               end
    type = if(channels == 1)
               if(self.pixel_size == 1)
                   OpenCV::Cv::CV_8UC1;
               elsif(self.pixel_size == 2)
                   OpenCV::Cv::CV_16UC1;
               else
                   raise "Unsupported pixel_size"
               end
           elsif channels == 3
               if(self.pixel_size == 3)
                   OpenCV::Cv::CV_8UC3;
               elsif(self.pixel_size == 6)
                   OpenCV::Cv::CV_16UC3;
               else
                   raise "Unsupported pixel_size"
               end
           else
                raise "Unsupported number of channels"
           end
    p = FFI::Pointer.new(:char,self.image.contained_memory_id)
    OpenCV::Cv::Mat.new(self.size.height,self.size.width,type,p)
end