Giter Club home page Giter Club logo

ika-meter-training-assistant's Introduction

IkaMeterTrainingAssistant

  • スプラトゥーン2の試合中に表示されるイカメーターの生存アイコンを検出する、分類器を生成するリポジトリです
  • このリポジトリには、正解要素のマーキングを支援WEBアプリと、opencv_traincascadeへの入力データを生成する機能を同梱しています

image image image image

  • 実際に生成した分類器の結果です。精度(体感)は80%くらいです。過学習している気がするし、パラメータ調整の試行錯誤が足りない気もする

TODO

使い方

  • bundle install
  • install [email protected]
  • リストアする
  • bundle exec rails s
  • ブラウザを開いてマーキングする
  • bundle exec rails r Build.execute && bundle exec rails r "Create.execute true" | sh
  • tmp/model/cascade.xml を使う

運用

ダンプ

bin/dump_db.sh

リストア

bin/restore_db.sh

画像を取り込む

Dir.glob("#{Rails.root}/lib/assets/20210521/*jpg").map.with_index(1) do |filename, index|
  file = File.open(filename)
  digest = Digest::MD5.hexdigest(file.read)
  if Dataset.find_by(digest: digest)
    Rails.logger.warn "skip!!!!!!!!!"
  else
    name = "#{Time.now.tap { |x| break "#{x.to_i}#{x.usec}" }}.jpg"
    file.rewind
    Dataset.create(image: { io: file, filename: name }, digest: digest )
  end
end

このリポジトリで生成した分類器を使って、あらかじめマークした状態で画像を取り込む

min = OpenCV::CvSize.new(64, 64)
scale_factor = 1.1
detector = OpenCV::CvHaarClassifierCascade::load("#{Rails.root}/ika-meter-training-assistant/tmp/model/cascade.xml")
Dir.glob("#{Rails.root}/lib/assets/0531/*.jpg").map do |filename|
  file = File.open(filename)
  digest = Digest::MD5.hexdigest(file.read)
  if Dataset.find_by(digest: digest)
    Rails.logger.warn "skip!!!!!!!!!"
  else
    image = OpenCV::CvMat.load(filename).copy
    croped_image = Crop.ikatako_meter_with_padding(image)
    name = "#{Time.now.tap { |x| break "#{x.to_i}#{x.usec}" }}.jpg"
    file.rewind
    ActiveRecord::Base.transaction do
      ImageProcessor::DeathMarkOverrider.new(croped_image).override!
      dataset = Dataset.create!(image: { io: file, filename: name }, digest: digest )
      detector.detect_objects(croped_image, min_size: min, min_neighbors: 5, scale_factor: scale_factor).each do |rect|
        dataset.dataset_temporary_positions.create!(x: rect.top_left.x + 450, y: rect.top_left.y, width: rect.bottom_right.x - rect.top_left.x, height: rect.bottom_right.y)
      end
    end
  end
end

cascade.xml を出力する

# DBからpositive.datを生成
be rails r Build.execute

# トレーニング
be rails r "Create.execute true" | sh

Links

ika-meter-training-assistant's People

Contributors

jiikko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.