Created
April 26, 2012 15:28
-
-
Save ser1zw/2500375 to your computer and use it in GitHub Desktop.
win32screenshotで撮ったスクリーンショットをruby-opencvのCvMatに読み込むサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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