Skip to content

Instantly share code, notes, and snippets.

@junpeitsuji
Last active August 29, 2015 14:11
Show Gist options
  • Save junpeitsuji/1a7c2a4e83c956d8c1e5 to your computer and use it in GitHub Desktop.
Save junpeitsuji/1a7c2a4e83c956d8c1e5 to your computer and use it in GitHub Desktop.
# coding: utf-8
require 'opencv'
require 'fileutils'
dropbox_dir = "/path/to/Dropbox" # ここだけ自分用に書き換えてください
# 0 番だと Mac のインカメラが選択されてしまうので 1 番を選択
capture = OpenCV::CvCapture.open 1
# カメラの起動を待つ
sleep(5)
image = capture.query
image = image.resize OpenCV::CvSize.new 640, 360
day = Time.now
day_string = day.strftime("%Y-%m-%d")
time_string = day.strftime("%H-%M-%S")
dir_path = "#{dropbox_dir}/ouchi-hack/#{day_string}/"
FileUtils.mkdir_p(dir_path) unless FileTest.exist?(dir_path)
path = "#{dir_path}#{time_string}.jpg"
puts path
image.save path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment