91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 4KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-03
  • 語言: Python
  • 標簽: 圍棋??go??python??ocr??sgf??

資源簡介

一個簡單實用的Python3源代碼,供圍棋截屏圖片掃描成通用的sgf格式
To use the script: python go-ocr.py images

資源截圖

代碼片段和文件信息

#!/usr/bin/env?python

from?PIL?import?Image
import?os
import?string
import?sys

image_dir?=?sys.argv[1]

WHITE?=?(255?255?255)
BLACK?=?(0?0?0)

BORDER?=?9
INTERVAL?=?19

#?use?a?small?offset?from?intersection?to?make?sure?we?don‘t?grab?a
#?black?pixel?from?the?grid?line?as?opposed?to?a?black?pixel?from?a?stone
OFFSET?=?3

#?TL?=?Top?Left??TR?=?Top?Right
#?BL?=?Bottom?Left??BR?=?Bottom?Right
#?the?corner?you?want?the?image?flipped?from
ORIGIN_CORNER?=?‘TR‘
#?the?corner?you?want?the?image?flipped?to
TARGET_CORNER?=?‘TL‘


def?transpose_image(image?x_lines?y_lines):
????transpose_matrix?=?{
????????(‘TL‘?‘TR‘):?‘V‘
????????(‘TL‘?‘BL‘):?‘H‘
????????(‘TL‘?‘BR‘):?‘HV‘

????????(‘TR‘?‘TL‘):?‘V‘
????????(‘TR‘?‘BL‘):?‘HV‘
????????(‘TR‘?‘BR‘):?‘H‘

????????(‘BL‘?‘TL‘):?‘H‘
????????(‘BL‘?‘TR‘):?‘HV‘
????????(‘BL‘?‘BR‘):?‘V‘

????????(‘BR‘?‘TL‘):?‘HV‘
????????(‘BR‘?‘TR‘):?‘H‘
????????(‘BR‘?‘BL‘):?‘V‘}

????if?TARGET_CORNER?==?‘TL‘:
????????x_string?=?y_string?=?string.ascii_letters
????elif?TARGET_CORNER?==?‘TR‘:
????????x_string?=?string.ascii_letters[19?-?x_lines:19]
????????y_string?=?string.ascii_letters
????elif?TARGET_CORNER?==?‘BL‘:
????????x_string?=?string.ascii_letters
????????y_string?=?string.ascii_letters[19?-?y_lines:19]
????elif?TARGET_CORNER?==?‘BR‘:
????????x_string?=?string.ascii_letters[19?-?x_lines:19]
????????y_string?=?string.ascii_letters[19?-?y_lines:19]

????for?instruction?in?transpose_matrix[(ORIGIN_CORNER?TARGET_CORNER)]:
????????if?instruction?==?‘H‘:
????????????image?=?image.transpose(Image.FLIP_TOP_BOTTOM)
????????if?instruction?==?‘V‘:
????????????image?=?image.transpose(Image.FLIP_LEFT_RIGHT)

????return?image?x_string?y_string


for?root?dir?files?in?os.walk(image_dir):
????for?image?in?files:
????????path?=?os.path.join(root?image)
????????try:
????????????im?=?Image.open(path)
????????except:
????????????print((“Cannot?open?‘{}‘.?Not?supported?or?not?an?image?file“.format(path)))
????????????continue

????????width?height?=?im.size
????????#x_lines?=?width?/?INTERVAL
????????#y_lines?=?height?/?INTERVAL
????????x_lines?=?int(width?/?INTERVAL)
????????y_lines?=?int(height?/?INTERVAL)

????????im?x_string?y_string?=?transpose_image(im?x_lines?y_lines)

????????#?deduct?1?from?total?lines?because?first?line?starts?on?offset
????????x_lines?=?x_lines?-?1
????????y_lines?=?y_lines?-?1

????????rgbimg?=?im.convert(‘RGB‘)
????????pixels?=?rgbimg.load()

????????coords?=?{
????????????‘AB‘:?[]
????????????‘AW‘:?[]}

????????index_x_string?=?0
????????for?x?in?range(BORDER?(INTERVAL?*?x_lines)?+?INTERVAL?INTERVAL):
????????????index_y_string?=?0
????????????for?y?in?range(BORDER?(INTERVAL?*?y_lines)?+?INTERVAL?INTERVAL):
????????????????#?get?pixel?using?no?offset:
????????????????#???if?it‘s?white?then?it‘s?a?white?stone
????????????????#???if?it‘s?black:
????????????????#?????get?pixel?using?offset:
????????????????#???????if?it‘s?black?then?it‘s?a?black?stone
????????????????#??

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-01-07?11:12??go-ocr\
?????文件????????3801??2020-01-06?16:45??go-ocr\go-ocr.py
?????目錄???????????0??2020-01-07?10:58??go-ocr\images\
?????文件?????????485??2013-04-03?12:41??go-ocr\images\image_1.png
?????文件??????????99??2020-01-06?22:51??go-ocr\images\image_1.sgf
?????文件?????????663??2013-04-03?12:41??go-ocr\images\image_2.png
?????文件?????????151??2020-01-06?22:51??go-ocr\images\image_2.sgf
?????文件?????????171??2020-01-07?11:12??go-ocr\README.md

評論

共有 條評論