画像を読む 08

画像データを macOSのスピーチ機能で読むプログラムを書いています。前ページでも書いたように、開発の大体の方向はありますが、最終的な形を現在考えている訳ではありません。制作ノートと思って読んでください。



ダウンロード:08PixelPoet.livecode
ビデオの実際のLiveCodeスタックです。ダウンロードしてスクリプトが見れます。
参考になるようなスクリプトがあったら自由に使ってください
下にスクリプトの一部を書き出しています。

ピクセル・カラー ポエト

ワーク・ウインドウ「Poem」を作って、そちらがメインで動作が見えるようにしました。

メイン・スタック「nabWd」のスクリプト
command setMosaic 
   set the width of image "tMosaic" of stack "LWd" to the width of image "dropImageS" of stack "navWd"
   set the height of image "tMosaic" of stack "LWd" to the height of image "dropImageS" of stack "navWd"
   set the imagedata of image "tMosaic" of stack "LWd" to the imagedata of image "dropImageS" of stack "navWd"
   set the rect of image "tMosaic" of stack "LWd" to the rect of cd 1 of stack "LWd" 
end setMosaic

command visualHideMosaic
   --   repeat with i=2 to 100 step 2
   set the blendlevel of image "tMosaic" of stack "LWd" to 0
   wait 120
   --end repeat
   repeat with i=2 to 100 step 2
      set the blendlevel of image "tMosaic" of stack "LWd" to i
   end repeat
end visualHideMosaic

command readSpeech pText
   put item 1 of the label of btn "tName" of stack "navWd" into tName
   put the hilitedButtonName of grp "readSpeed" of stack "navWd" into tSpeed
   revSetSpeechVoice tName
   revSetSpeechVolume 130
   revSetSpeechSpeed tSpeed
   revspeak pText
end readSpeech

function format8bit tValue
   if the length of tValue < 8 then
      repeat until the length of tValue = 8
         put "0" before tValue
      end repeat
   end if
   return tValue
end format8bit


メイン・スタック「nabWd」cd 1のスクリプト
global gMosaicRow, gMosaicColumn, gMosaicColor

on dragEnter
   set the acceptDrop to true
end dragEnter

on dragDrop
   put dragData["files"] into tPath
   if word -1 of the target is not quote&"dropImage""e then 
      beep
      exit to top
   end if
   lock screen
   set the filename of the target to ("file://"&tPath)
   --   setImageSizeLoc the width of this cd / 2
   -- オリジナル・イメージデータ = the tOriginalData of image "dropImage"
   set the tOriginalData of image "dropImage" to the imageData of image "dropImage"
   set the tFormattedwidth of image "dropImage" to the formattedwidth of image "dropImage" 
   set the tFormattedheight of image "dropImage" to the formattedheight of image "dropImage" 
   put the tOriginalData of image "dropImage" into fld "tBinary"
   setImageSizeLoc the width of this cd / 2
   put "ASCII" into fld "convertTitle" 
   set the thumbpos of sb "sbBar" to 10
   set the filename of image "dropImageS" of stack "navWd" to ("file://"&tPath)
   set the tImageData of image "dropImageS" of stack "navWd" to \
         the imageData of image "dropImageS" of stack "navWd"
   set the filename of image "tOriginal" of stack "LWd" to ("file://"&tPath)
   hide image "tMosaic" of stack "LWd"
   -- 始めに左上のモザイクにセット
   hide grc "colorSq" of stack "LWd" 
   put "" into fld "poem" of stack "LWd"
end dragDrop

command setImageSizeLoc pDefaultSize
   put the rect of image "dropImage" into tImageRect
   put the formattedWidth of image "DropImage" into tOriginalWidth
   put the formattedHeight of image "DropImage" into tOriginalHeight
   
   if tOriginalWidth >= tOriginalHeight then
      set the width of img "dropImage" to pDefaultSize
      set the Height of img "dropImage" to tOriginalHeight * pDefaultSize / tOriginalWidth
   else
      set the height of img "dropImage" to pDefaultSize
      set the width of img "dropImage" to tOriginalWidth * pDefaultSize / tOriginalHeight
   end if
   set the rect of img "dropImage" to tImageRect
   set the rect of img "dropImageS" to tImageRect
end setImageSizeLoc

command mosaicColorArray
  -- put the imageData of image "dropImageS" into tBinary
  put the imagedata of image "dropImageS" of stack "navWd" into tBinary
  put the length of tBinary into tLength

  -- grc "colorSq" のサイズ
  put the width of image "dropImageS" of stack "navWd" into tWidthS
  set the width of grc "colorSq" of stack "LWd" to the width of stack "LWd" / tWidthS
  put the height of image "dropImageS" of stack "navWd" into tHeightS
  set the height of grc "colorSq" of stack "LWd" to the height of stack "LWd" / tHeightS
  put "" into gMosaicColor

  put 0 into tCount
  repeat with i = 1 to (tLength - 4) step 4  --this is column

     add 1 to tCount  --this is row
     if tCount = tWidthS then 
        put cr into tConj 
        put 0 into tCount
     else 
        put tab into tConj 
     end if

     put charToNum(char i of tBinary) & comma & \
           charToNum(char (i + 1)  of tBinary) & comma & \
           charToNum(char (i + 2) of tBinary) & comma & \
           charToNum(char (i + 3) of tBinary)  & tConj after gMosaicColor
  end repeat

  put gMosaicColor into fld "tBinary"  -- RGB numbers 
  put "Decimal" into fld "convertTitle" 
  put gMosaicColor into tColorArray
  split tColorArray by column  

  -- モザイクのカラー グローバルの gMosaicColor を tColorArray に入れ split tColorArray by column
  -- 始めに左上のモザイクにセット
  set the backgroundcolor of grc "colorSq" of stack "LWd" to item 2 to 4 of line 1 of tColorArray[1]
end mosaicColorArray

command mosaicLocArray
  put "" into gMosaicRow
  put "" into gMosaicColumn
  put the imageData of image "dropImageS" into tBinary
  -- put the length of tBinary into tLength
  put the width of stack "LWd" / (the width of image "dropImageS" of stack "navWd" * 2) into tHalfWidth
  put the height of stack "LWd" / (the height of image "dropImageS" of stack "navWd" * 2) into tHalfHeight
  -- put tHalfWidth,tHalfHeight & tab into gMosaicLoc

  put tHalfWidth & comma into gMosaicRow
  repeat with i=1 to (the width of image "dropImageS" of stack "navWd") -1 
     put tHalfWidth + i* (the width of stack "LWd" / the width of image "dropImageS" of stack "navWd") \
           & comma after gMosaicRow
  end repeat

  put gMosaicRow into tRow

  put tHalfHeight & comma into gMosaicColumn
  repeat with i=1 to (the height of image "dropImageS" of stack "navWd") -1 
     put tHalfHeight + i* (the height of stack "LWd" / the height of image "dropImageS" of stack "navWd") \
           & comma after gMosaicColumn
  end repeat
  put gMosaicColumn into tColumn

  -- 始めに左上のモザイクにセット
  set the loc of grc "colorSq" of stack "LWd" to item 1 of tRow, item 1 of tColumn   
end mosaicLocArray 

on openCard
   set the imagedata of image "dropImage" to the tWhite of image "dropImage"
   put "" into fld "tBinary"
   put "" into fld "ConvertTitle"
   set the tOriginalData of image "dropImage" to the tWhite of image "dropImage"
   set the hilite of btn "open2nd" to false
   set the thumbpos of sb "sbBar" to 10
   put "" into fld "poem" of stack "LWd"
end openCard

on closeCard
   set the imagedata of image "dropImage" to the tWhite of image "dropImage"
   put "" into fld "tBinary"
   set the tOriginalData of image "dropImage" to the tWhite of image "dropImage"
   put "" into fld "convertTitle" 
end closeCard


スクロール・バー「sbBar」のスクリプト
global gMosaicColor, gMosaicLoc

on mouseUp
   set the cursor to watch
   revspeak ""
   put "" into fld "Poem" of stack "LWd" 
   set the poemColors of fld "poem" of stack "LWd" to ""
   put the rect of image "dropImage" into tRectImage
   put the width of image "dropImage" into tWidth
   put the height of image "dropImage" into tHeight
   set the numberFormat to "#"
   put  (the thumbpos of sb "sbBar" / 100) into tPercent
   set the width of image "dropImageS" to tWidth
   set the height of image "dropImageS" to tHeight
   set the imagedata of image "dropImageS" to the tOriginalData of image "dropImage"
   set the width of image "dropImageS" to tWidth * tPercent
   set the height of image "dropImageS" to tHeight * tPercent
   
   set the width of image "dropImage" to the width of image "dropImageS"
   set the height of image "dropImage" to the height of image "dropImageS"
   set the imagedata of image "dropImage" to the imagedata of image "dropImageS"
   set the tImageData of image "dropImageS" to the imagedata of image "dropImageS" 
   put the imagedata of image "dropImageS" into fld "tBinary"
   set the rect of image "dropImage" to tRectImage
   put "ASCII" into fld "convertTitle" 
   setMosaic
   
   -- grc "colorSq" のサイズ調整
   hide grc "colorSq" of stack "LWd"
 
   -- モザイクのカラー・アレイ
   mosaicColorArray
   -- put gMosaicColor[2]  --アレイテスト
   
   -- モザイクのロケーション・アレイ
   mosaicLocArray
   
   set the blendlevel of image "tMosaic" of stack "LWd" to 0
   show image "tMosaic" of stack "LWd"
    hide grc "colorSq" of stack "LWd"
   if "LWd" is among the lines of openStacks() is true then put "" into fld "tBinary" of stack "navWd" 
   visualHideMosaic
end mouseUp


ボタン「read」のスクリプト
on mouseUp
   put fld "tBinary" into tBinary
   readSpeech tBinary
end mouseUp




バイナリを10進数に

イメージとビデオ(ミリセコンド間隔)




アーチスト:小島健治 / Artist: Kenji Kojima

アーチスト:小島健治
kenjikojima.com


クリエイティブ・コモンズ
Attribution-NonCommercial-NoDerivatives

Click and Go to PayPal

日本からのドネーションは こちらをクリック

LiveCode 6 初心者開発入門