2019年10月18日金曜日

tf.aws.sh.resource.list.txt

aws_dynamodb_table  tbl01
aws_dynamodb_table  tbl11
aws_s3_bucket       awss3bkt001
aws_s3_bucket       awss3bkt002

tf.aws.bat

@rem
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

set "cmd_filename=%~nx0"

set "AWS_ACCESS_KEY_ID=aaaaaaaaaa"
set "AWS_SECRET_ACCESS_KEY=ssssssssss"
set "AWS_DEFAULT_REGION=ap-northeast-1"

@rem set "TF_LOG=DEBUG"
set "CHECKPOINT_DISABLE=true"

set "TerraformCmd=.\terraform.exe"
set "TerraformCmd_apply_opt=-auto-approve"
set "TerraformCmd_fmt_opt=-recursive ."

set "dot_cmd=uuuuuuuuuu\PlantUML\graphviz\release\bin\dot.exe"

set "file_resource_list_txt=!cmd_filename!.resource.list.txt"
set "file_txt=!cmd_filename!.txt"
set "file_tf=!cmd_filename!.tf"
set "file_tmp_tf=!cmd_filename!.tmp.tf"
set "file_png=!cmd_filename!.png"


@rem ================
@rem main.
@rem ================
:main
if "%1"=="" (
  goto :printUsage
) else if "%1"=="apply" (
  goto :TerraformCmd_apply
) else if "%1"=="fmt" (
  goto :TerraformCmd_fmt
) else if "%1"=="import" (
  goto :TerraformCmd_import
) else if "%1"=="plan" (
  goto :TerraformCmd_plan
) else if "%1"=="init" (
  goto :TerraformCmd_init
) else if "%1"=="remove" (
  goto :TerraformCmd_remove
) else if "%1"=="showInfo" (
  goto :TerraformCmd_showInfo
) else (
  goto :printUsage
)
goto :eof


@rem ================
@rem Print usage.
@rem ================
:printUsage
  echo Usage:
  echo   !cmd_filename! import
  echo   !cmd_filename! apply
  echo   !cmd_filename! fmt
  echo   !cmd_filename! plan
  echo   !cmd_filename! init
  echo   !cmd_filename! remove
  echo   !cmd_filename! showInfo
goto :eof


@rem ================
@rem Filesystem delete files.
@rem ================
:Filesystem_deleteFiles
  for %%z in (
    %*
  ) do (
    set "filePath=%%z"
    if exist "!filePath!" (
      echo ^
        del "!filePath!"
        del "!filePath!"
    )
    if exist "!filePath!" (
      echo Did not delete file "${filePath}".
      exit /b 11
    )
  )
goto :eof


@rem ================
@rem TerraformFile Make empty file_tmp_tf.
@rem ================
:TerraformFile_makeEmptyTf
  if not exist "!file_resource_list_txt!" (
    echo Does not exist file "!file_resource_list_txt!".
    exit /b 21
  )
  for /f "usebackq tokens=1,2 delims= " %%y in (
    `type "!file_resource_list_txt!"`
  ) do (
    set "aws_resource_type=%%y"
    set "aws_resource_name=%%z"
    call :TerraformFile_printEmptyTf ^
      "!aws_resource_type!" ^
      "!aws_resource_name!" ^
      >> "!file_tmp_tf!"
  )
goto :eof


@rem ================
@rem TerraformFile Make one empty resource tf.
@rem ================
:TerraformFile_printEmptyTf
  set "aws_resource_type=%~1"
  set "aws_resource_name=%~2"
  set "tf_resource_name=!aws_resource_name!_tf"
  echo resource "!aws_resource_type!" "%!tf_resource_name!" {
  echo }
goto :eof


@rem ================
@rem Terraform cmd.
@rem ================
:TerraformCmd
  for %%z in (
    %*
  ) do (
    set "tf_commamd=%%z"
    set "tf_commamd=!tf_commamd:"=!"
    @rem "
    echo # ^
      "!TerraformCmd!" !tf_commamd!
      "!TerraformCmd!" !tf_commamd!
    if not !errorlevel!==0 (
      echo Exit code is !errorlevel!.
      exit /b 22
    )
  )
goto :eof


@rem ================
@rem Terraform Show info.
@rem ================
:TerraformCmd_showInfo
  echo # ^
    type "!file_resource_list_txt!"
    type "!file_resource_list_txt!"
  call :TerraformCmd ^
    "version" ^
    "providers" ^
    "validate -json"
goto :eof


@rem ================
@rem Terraform apply.
@rem ================
:TerraformCmd_apply
  call :Filesystem_deleteFiles ^
    "!file_txt!" ^
    "!file_tmp_tf!" ^
    "!file_png!"
  call :TerraformCmd_showInfo
  call :TerraformCmd_init
  call :TerraformCmd_plan
  call :TerraformCmd "apply !TerraformCmd_apply_opt!"
goto :eof


@rem ================
@rem Terraform fmt.
@rem ================
:TerraformCmd_fmt
  call :TerraformCmd "fmt !TerraformCmd_fmt_opt!"
goto :eof


@rem ================
@rem Terraform init.
@rem ================
:TerraformCmd_init
  call :TerraformCmd_fmt
  call :TerraformCmd "init"
goto :eof


@rem ================
@rem Terraform plan.
@rem ================
:TerraformCmd_plan
  call :TerraformCmd "plan"
goto :eof


@rem ================
@rem Terraform remove.
@rem ================
:TerraformCmd_remove
  if not exist "!file_tf!" (
    echo Does not exist file "!file_tf!".
    exit /b 23
  )
  ren "!file_tf!" "!file_tf!.tmp"
  call :TerraformCmd_apply
  ren "!file_tf!.tmp" "!file_tf!"
goto :eof


@rem ================
@rem Terraform import.
@rem ================
:TerraformCmd_import
  call :Filesystem_deleteFiles ^
    "terraform.tfstate" ^
    "!file_txt!" ^
    "!file_tf!" ^
    "!file_tmp_tf!" ^
    "!file_png!"
  call :TerraformCmd_showInfo

  call :TerraformFile_makeEmptyTf
  echo # ^
    type "!file_tmp_tf!"
    type "!file_tmp_tf!"
  call :TerraformCmd_init

  @rem Make file_txt.
  echo # ^
    type "!file_resource_list_txt!"
    type "!file_resource_list_txt!"

  for /f "usebackq tokens=1,2 delims= " %%i in (
    `type "!file_resource_list_txt!"`
  ) do (
    set "aws_resource_type=%%i"
    set "aws_resource_name=%%j"
    set "tf_resource_name=!aws_resource_name!_tf"
    echo # ^
      aws_resource_type=!aws_resource_type! ^
      aws_resource_name=!aws_resource_name! ^
      tf_resource_name=!tf_resource_name!

    echo # ^
      "!TerraformCmd!" import "!aws_resource_type!.!tf_resource_name!" !aws_resource_name!
      "!TerraformCmd!" import "!aws_resource_type!.!tf_resource_name!" !aws_resource_name!
    if not !errorlevel!==0 exit /b 1

    echo # ^
      "!TerraformCmd!" state show -no-color "!aws_resource_type!.!tf_resource_name!"
      "!TerraformCmd!" state show -no-color "!aws_resource_type!.!tf_resource_name!" >> "!file_txt!"
    if not !errorlevel!==0 exit /b 2

  )
  call :Filesystem_deleteFiles ^
    "!file_tmp_tf!"
  ren "!file_txt!" "!file_tf!"
  call :TerraformCmd_fmt
  ren "!file_tf!" "!file_txt!"

  @rem Make file_tf.
  for /f "usebackq tokens=1* delims=" %%i in (
    `type "!file_txt!"`
  ) do (
    set "line=%%i"

    set "line=!line: arn = # arn !"
    set "line=!line: id = # id !"
    set "line=!line: bucket_domain_name = # bucket_domain_name !"
    set "line=!line: bucket_regional_domain_name = # bucket_regional_domain_name !"
    (echo !line!) >> "!file_tf!"
  )

  call :TerraformCmd_fmt

  echo # ^
    type "!file_tf!"
    type "!file_tf!"

  call :TerraformCmd_plan

  @rem Make file_png.
  call :L_mkPng

  @rem pause

goto :eof


@rem ================
@rem Make file_png.
@rem ================
:L_mkPng
if exist "!dot_cmd!" (
  echo # ^
    "!TerraformCmd!" graph ^| "!dot_cmd!" -Tpng ^> "!file_png!"
    "!TerraformCmd!" graph | "!dot_cmd!" -Tpng > "!file_png!"
)
goto :eof

terraform.exe-h.txt

Usage: terraform [-version] [-help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    0.12upgrade        Rewrites pre-0.12 module source code for v0.12
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    push               Obsolete command for Terraform Enterprise legacy (v1)
    state              Advanced state management

2019年8月12日月曜日

mkCascadeDetect.bat

call .\venv\Scripts\activate
python mkCascadeDetect.py
deactivate

cvtIcon.py

import cv2
import glob
import os
import os.path
import re
import numpy as np

ocvIcoDirPath="data/ico-96"
# def binary_threshold(path):def binary_threshold(img):
    # img = cv2.imread(path)    # grayed = cv2.cvtColor(img, cv2.IMREAD_GRAYSCALE)    grayed = img
    under_thresh = 105    upper_thresh = 145    maxValue = 255    th, drop_back = cv2.threshold(grayed, under_thresh, maxValue, cv2.THRESH_BINARY)
    th, clarify_born = cv2.threshold(grayed, upper_thresh, maxValue, cv2.THRESH_BINARY_INV)
    merged = np.minimum(drop_back, clarify_born)
    merged = drop_back
    return merged

def mask_blue(path):
    img = cv2.imread(path)
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

    blue_min = np.array([210*180/240, 170*100/240, 200*100/240], np.uint8)
    blue_max = np.array([230*180/240, 190*100/240, 230*100/240], np.uint8)

    blue_region = cv2.inRange(hsv, blue_min, blue_max)
    white = np.full(img.shape, 255, dtype=img.dtype)
    background = cv2.bitwise_and(white, white, mask=blue_region)  # detected blue area becomes white
    inv_mask = cv2.bitwise_not(blue_region)  # make mask for not-blue area    extracted = cv2.bitwise_and(img, img, mask=inv_mask)

    masked = cv2.add(extracted, background)

    return masked

def morph(img):
    kernel = np.ones((3, 3),np.uint8)
    opened = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel, iterations=2)
    # opened = cv2.morphologyEx(img, cv2.MORPH_ERODE, kernel, iterations=2)    return opened

def morph_and_blur(img):
    kernel = np.ones((3, 3),np.uint8)
    m = cv2.GaussianBlur(img, (3, 3), 0)
    m = cv2.morphologyEx(m, cv2.MORPH_OPEN, kernel, iterations=2)
    m = cv2.GaussianBlur(m, (5, 5), 0)
    return m

def icoFile(icoFilePath):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    # gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)    # gray = cv2.cvtColor(img, cv2.IMREAD_COLOR)    # gray = mask_blue(gray)    gray = morph(gray)
    # gray = binary_threshold(icoFilePath)    # cv2.imwrite(detectedFilePath, gray)    return gray

def resize_image(img, size):
    # size is enough to img    img_size = img.shape[:2]
    if img_size[0] > size[1] or img_size[1] > size[0]:
        raise Exception("img is larger than size")

    # centering    row = (size[1] - img_size[0]) // 2    col = (size[0] - img_size[1]) // 2    resized = np.zeros(list(size) + [img.shape[2]], dtype=np.uint8)
    resized[row:(row + img.shape[0]), col:(col + img.shape[1])] = img

    # filling    mask = np.full(size, 255, dtype=np.uint8)
    mask[row:(row + img.shape[0]), col:(col + img.shape[1])] = 0    filled = cv2.inpaint(resized, mask, 3, cv2.INPAINT_TELEA)

    return filled

icoFilePaths = glob.glob(str(ocvIcoDirPath) + "/*")
pathname = ocvIcoDirPath + "-2"os.makedirs(pathname,  exist_ok=True)
for icoFilePath in icoFilePaths:
    basename = os.path.basename(icoFilePath)
    icoFilePath = re.sub('[/\\\\]', "/", icoFilePath)
    img = cv2.imread(icoFilePath)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = binary_threshold(gray)
    # gray = morph(gray)    # gray = morph_and_blur(gray)    # gray = resize_image(gray, (210, 210))    cv2.imwrite(pathname + "/" + basename, gray)
    gray = gray

2019年8月5日月曜日

getSitImg.py

import os
import re
import requests
import time
from bs4 import BeautifulSoup

staSitLst = {
    # jreast    #    # https://www.jreast.co.jp/estation/stations/    #     </td><td style="width:99px;"><A href="http://www.jreast.co.jp/estation/stations/1039.html" target = "_blank" onclick="openMap('1039');return false;">東京</A>    #    # https://www.jreast.co.jp/estation/stations/1039.html    #                  <img src="img/floormap/1039_1f.png" alt="東京駅 1F構内図">    #    # https://www.jreast.co.jp/estation/stations/img/floormap/1039_1f.png    "jreast": {
        "itemEnable": False,        "ocvSitUrl": "https://www.jreast.co.jp/",        "staLstUrl": "https://www.jreast.co.jp/estation/stations",        "reImgLstUrl": "^(http://www\.jreast\.co\.jp/estation/stations/[0-9]+\..+)$",        "reImgLstId": "\\1",        "fmtImgLstUrl": "{}",        "reStaImgUrl": "^(img/floormap/.+\..+)$",        "reStaImgId": "\\1",        "fmtStaImgUrl": "https://www.jreast.co.jp/estation/stations/{}",        "reStaImgUrlFilBas": "^.*img/floormap/([^.]+)\.[^.]+.*$",        "reStaImgUrlFilExt": "^.*img/floormap/[^.]+\.([^.]+)$",        "regStaImgUrlFilBas": "\\1",        "regStaImgUrlFilExt": "\\1",        "imgUrl": "{}/{}",        "z": "z"    },    # keikyu    #    # https://www.keikyu.co.jp/train-info/kakueki/index.html    #     <area coords="206,48,426,88" href="/train-info/kakueki/KK01.html" alt="品川" data-imagemap-rollover-url="/assets/image/train-info/kakueki/index_img_route_KK01.png">    #    # https://www.keikyu.co.jp/train-info/kakueki/KK01.html    #     <img src="/assets/image/train-info/kakueki/KK01/img_03.png" alt="品川駅の設備図です">    #    # https://www.keikyu.co.jp/assets/image/train-info/kakueki/KK01/img_03.png    "keikyu": {
        "itemEnable": False,        "ocvSitUrl": "https://www.keikyu.co.jp/",        "staLstUrl": "https://www.keikyu.co.jp/train-info/kakueki/index.html",        "reImgLstUrl": "^(/train-info/kakueki/KK[0-9][0-9]\.htm.*)",        "reImgLstId": "\\1",        "fmtImgLstUrl": "https://www.keikyu.co.jp{}",        "reStaImgUrl": "^(/assets/image/train-info/kakueki/KK[0-9][0-9]/img_03\..+)$",        "reStaImgId": "\\1",        "fmtStaImgUrl": "https://www.keikyu.co.jp{}",        "reStaImgUrlFilBas": "^.*/assets/image/train-info/kakueki/(KK[0-9][0-9])/img_03.[^.]+.*$",        "reStaImgUrlFilExt": "^.*/assets/image/train-info/kakueki/KK[0-9][0-9]/img_03.([^.]+).*$",        "regStaImgUrlFilBas": "\\1",        "regStaImgUrlFilExt": "\\1",        "imgUrl": "{}/{}",        "z": "z"    },    # tokyometro    #    # https://www.tokyometro.jp/station/index03.html    #                   <a href="./akihabara/index.html">    #    # https://www.tokyometro.jp/station/akihabara/yardmap/index.html#adjacent    #               <p class="v2_yardmapImg"><img src="../../yardmap_img/_station_%E7%A7%8B%E8%91%89%E5%8E%9F_yardmap_images_yardmap.jpg" alt="" class="v2_js-yardmapImg"></p>    #               <p class="v2_yardmapImg"><img src="../../yardmap_img/figure_yardmap_ayase.gif" alt="" class="v2_js-yardmapImg"></p>    #    # https://www.tokyometro.jp/station/yardmap_img/_station_%E7%A7%8B%E8%91%89%E5%8E%9F_yardmap_images_yardmap.jpg    # https://www.tokyometro.jp/station/yardmap_img/figure_yardmap_ayase.gif    "tokyometro": {
        "itemEnable": False,        "ocvSitUrl": "https://www.tokyometro.jp/",        "staLstUrl": "https://www.tokyometro.jp/station/index03.html",        "reImgLstUrl": "^\./(.+)/index\.html$",        "reImgLstId": "\\1",        "fmtImgLstUrl": "https://www.tokyometro.jp/station/{}/yardmap/index.html",        "reStaImgUrl": "^\.\./\.\./(yardmap_img/.+\..+)$",        "reStaImgId": "\\1",        "fmtStaImgUrl": "https://www.tokyometro.jp/station/{}",        "reStaImgUrlFilBas": "^.*https://www.tokyometro.jp/station/([^/]+)/yardmap/index.html.*$",        "reStaImgUrlFilExt": "^.*/yardmap_img/.+\.([^.]+).*$",        "regStaImgUrlFilBas": "\\1",        "regStaImgUrlFilExt": "\\1",        "imgUrl": "{}/{}",        "z": "z"    }

}

ocvItvlt = 10
def getStaImg(ocvSit, imgLstUrl, staImgUrl):
    reStaImgUrlFilBas = staSitLst[ocvSit]["reStaImgUrlFilBas"]
    regStaImgUrlFilBas = staSitLst[ocvSit]["regStaImgUrlFilBas"]
    reStaImgUrlFilExt = staSitLst[ocvSit]["reStaImgUrlFilExt"]
    regStaImgUrlFilExt = staSitLst[ocvSit]["regStaImgUrlFilExt"]
    imgFilBas = re.sub(reStaImgUrlFilBas, regStaImgUrlFilBas, imgLstUrl + "," + staImgUrl)
    imgFilExt = re.sub(reStaImgUrlFilExt, regStaImgUrlFilExt, imgLstUrl + "," + staImgUrl)
    fmtImgDirPth = "/".join(["data", "_img", "{}", "floormap"])
    fmtImgFilPth = "/".join([fmtImgDirPth, "{}.{}"])
    imgDirPth = fmtImgDirPth.format(ocvSit)
    imgFilPth = fmtImgFilPth.format(ocvSit, imgFilBas, imgFilExt)
    print("# staImgUrl=" + staImgUrl)
    print("# imgFilPth=" + imgFilPth)
    os.makedirs(imgDirPth, exist_ok=True)
    staImg = requests.get(staImgUrl)
    with open(imgFilPth, "wb") as file:
            file.write(staImg.content)
    time.sleep(ocvItvlt)

def getImgLst(ocvSit, imgLstUrl):
    reStaImgUrl = staSitLst[ocvSit]["reStaImgUrl"]
    reStaImgId = staSitLst[ocvSit]["reStaImgId"]
    fmtStaImgUrl = staSitLst[ocvSit]["fmtStaImgUrl"]
    staImgPag = requests.get(imgLstUrl)
    soup = BeautifulSoup(staImgPag.text, "lxml")
    staImgImgTags = soup.find_all("img", src=re.compile(reStaImgUrl))
    for staImgImgTag in staImgImgTags:
        staImgId = re.sub(reStaImgUrl, reStaImgId, staImgImgTag["src"])
        staImgUrl = fmtStaImgUrl.format(staImgId)
        print("# staImgId=" + staImgId + ", staImgUrl=" + staImgUrl)
        getStaImg(ocvSit, imgLstUrl, staImgUrl)

def getStaLst(ocvSit, staLstUrl):
    reImgLstUrl = staSitLst[ocvSit]["reImgLstUrl"]
    reImgLstId = staSitLst[ocvSit]["reImgLstId"]
    fmtImgLstUrl = staSitLst[ocvSit]["fmtImgLstUrl"]
    staLstPag = requests.get(staLstUrl)
    soup = BeautifulSoup(staLstPag.text, "lxml")
    staPagATags = soup.find_all("a", href=re.compile(reImgLstUrl))
    for staPagATag in staPagATags:
        staPagId = re.sub(reImgLstUrl, reImgLstId, staPagATag["href"])
        imgLstUrl = fmtImgLstUrl.format(staPagId)
        print("# staPagId=" + staPagId + ", imgLstUrl=" + imgLstUrl)
        getImgLst(ocvSit, imgLstUrl)

def getSitLst(staSitLst):
    for staSitNam in staSitLst.keys():
        if staSitLst[staSitNam]["itemEnable"] == True:
            staLstUrl = staSitLst[staSitNam]["staLstUrl"]
            print("# staSitNam=" + staSitNam + ", staLstUrl=" + staLstUrl)
            getStaLst(staSitNam, staLstUrl)

def getSit():
    getSitLst(staSitLst)

getSit()

2019年7月17日水曜日

mkCascadeDetect.py

import cv2
import glob
import os
import os.path
import re
import numpy as np

ocvIcoDirPath="data/ico"ocvMdlDirPath="data/mdl"ocvRstDirPath="result"ocvTgtDirPath="data/_img/tokyometro/floormap"# ocvTgtDirPath="data/pos/atm.jpg.d"# ocvTgtDirPath="data/pos/baby.jpg.d"# ocvTgtDirPath="data/pos/elv.jpg.d"# ocvTgtDirPath="data/pos/esc.jpg.d"# ocvTgtDirPath="data/pos/001275320-baby.jpg.d"
ocvTgtDirPaths = [
    "data/_img/jreast/floormap",    "data/_img/keikyu/floormap",    "data/_img/tokyometro/floormap",]

# def binary_threshold(img):#     # img = cv2.imread(path)#     grayed = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)#     # grayed = img#     under_thresh = 105#     upper_thresh = 145#     maxValue = 255#     th, drop_back = cv2.threshold(grayed, under_thresh, maxValue, cv2.THRESH_BINARY)#     th, clarify_born = cv2.threshold(grayed, upper_thresh, maxValue, cv2.THRESH_BINARY_INV)#     merged = np.minimum(drop_back, clarify_born)#     return merged
# def mask_blue(img):#     # img = cv2.imread(path)#     hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)##     blue_min = np.array([210*180/240, 170*100/240, 200*100/240], np.uint8)#     blue_max = np.array([230*180/240, 190*100/240, 230*100/240], np.uint8)##     blue_region = cv2.inRange(hsv, blue_min, blue_max)#     white = np.full(img.shape, 255, dtype=img.dtype)#     background = cv2.bitwise_and(white, white, mask=blue_region)  # detected blue area becomes white##     inv_mask = cv2.bitwise_not(blue_region)  # make mask for not-blue area#     extracted = cv2.bitwise_and(img, img, mask=inv_mask)##     masked = cv2.add(extracted, background)##     return masked
# def morph(img):#     kernel = np.ones((3, 3),np.uint8)#     opened = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel, iterations=2)#     return opened
def detectTgtIco(tgtFilePath, icoFilePath):
    if os.name == 'nt':
        os.system("title " + tgtFilePath + " " + icoFilePath)
    icoFileName = re.sub('^.*[/\\\\]', "", icoFilePath)
    tgtFileName = re.sub('^.*[/\\\\]', "", tgtFilePath)
    cascadeXml = str(ocvMdlDirPath) + '/' + icoFileName + '.d/cascade.xml'    detectedFilePath = ocvRstDirPath + "/" + str(tgtFileName) + "." + str(icoFileName) + "." + "jpg"    if os.path.isfile(cascadeXml):
        print("# " + detectedFilePath)
        Cascade = cv2.CascadeClassifier(cascadeXml)
        root, ext = os.path.splitext(tgtFilePath)
        if ext == "gif":
            return        else:
            img = cv2.imread(tgtFilePath, cv2.IMREAD_COLOR)
        # gray = img        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        # gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)        # gray = cv2.cvtColor(img, cv2.IMREAD_COLOR)        # gray = mask_blue(gray)        # gray = morph(gray)        # gray = binary_threshold(img)        # cv2.imwrite(detectedFilePath, gray)        point = Cascade.detectMultiScale(gray, 1.1, 3)
        if len(point) > 0:
            print("points: " + str(len(point)))
            for rect in point:
                print(rect)
                (x, y, w, h) = rect
                cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 5)
            cv2.imwrite(detectedFilePath, img)
        # else:        #     print("no detect")
# def icoFile(ocvTgtDirPath, icoFilePath):#     tgtFilePaths = glob.glob(str(ocvTgtDirPath) + "/*")#     for tgtFilePath in tgtFilePaths:#         tgtFilePath = re.sub('[/\\\\]', "/", tgtFilePath)#         tgtFileFile(tgtFilePath, icoFilePath)
# def icoFiles(ocvTgtDirPath):#     icoFilePaths = glob.glob(str(ocvIcoDirPath) + "/*")#     for icoFilePath in icoFilePaths:#         ocvTgtDirPaths.append(icoFilePath)#         icoFilePath = re.sub('[/\\\\]', "/", icoFilePath)#         icoFile(ocvTgtDirPath, icoFilePath)
# def icoFilePaths(ocvTgtFilePath, ocvIcoFilePath):#     icoFilePaths = glob.glob(str(ocvIcoDirPath) + "/*")#     for icoFilePath in icoFilePaths:#         detectTgtIco(tgtFilePath, icoFilePath)
def tgtFilePath(ocvTgtFilePath):
    ocvIcoFilePaths = glob.glob(str(ocvIcoDirPath) + "/*")
    for ocvIcoFilePath in ocvIcoFilePaths:
        detectTgtIco(ocvTgtFilePath, ocvIcoFilePath)

    # for ocvTgtDirPath in tgtFilePaths:    #     icoFiles(ocvTgtFilePath)

# def tgtFilePath(ocvTgtFilePath):#     for ocvTgtDirPath in tgtFilePaths:#         icoFiles(ocvTgtDirPath)
# for tgtFilePath in ocvTgtDirPaths:#     tgtFilePath = re.sub('[/\\\\]', "/", tgtFilePath)#     icoDir(tgtFilePath)

def tgtDirPath(ocvTgtDirPath):
    ocvTgtFilePaths = glob.glob(str(ocvTgtDirPath) + "/*")
    for ocvTgtFilePath in ocvTgtFilePaths:
            tgtFilePath(ocvTgtFilePath)

def tgtDirPaths(ocvTgtDirPaths):
    for ocvTgtDirPath in ocvTgtDirPaths:
        tgtDirPath(ocvTgtDirPath)

tgtDirPaths(ocvTgtDirPaths)