Skip to content

Instantly share code, notes, and snippets.

@ser1zw
Created April 26, 2012 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ser1zw/2500375 to your computer and use it in GitHub Desktop.
Save ser1zw/2500375 to your computer and use it in GitHub Desktop.
win32screenshotで撮ったスクリーンショットをruby-opencvのCvMatに読み込むサンプル
# win32screenshotで撮ったスクリーンショットをruby-opencvのCvMatに読み込むサンプル
require 'opencv'
require 'win32/screenshot'
require 'tempfile'
include OpenCV
# (1) スクリーンショットを撮る
screenshot = Win32::Screenshot::Take.of(:desktop)
# (2) スクリーンショットの画像データを一時ファイルに書き込んでからCvMat.loadで読み込む
image = nil
Tempfile.open('screenshot') { |f|
# 画像ファイルを書きこむので、一時ファイルをバイナリモードに設定
f.binmode
# スクリーンショットの画像を一時ファイルに書き込む
f.write screenshot.bitmap
# 読み込む
image = CvMat.load(f.path)
}
# (3) 表示
GUI::Window.new('screenshot').show image
GUI::wait_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment