teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

for文を途中からしか記載していなかったので、全文入力しました。

2019/03/06 14:53

投稿

zuzu1984
zuzu1984

スコア31

title CHANGED
File without changes
body CHANGED
@@ -12,32 +12,37 @@
12
12
 
13
13
  【コード】
14
14
  ```python
15
+ picno = 1
15
- # -*^cording: utf-8 -*-
16
+ for i in range(5):
17
+ event_pic = testfld + '/Cut/988-3_no' + str(picno) + '.png'
18
+ print(picno)
16
19
 
20
+ #======================================
21
+ # グレースケール
22
+ mov_in = cv2.imread(event_pic, cv2.IMREAD_GRAYSCALE) # 画像ファイrの読み込み
23
+ if mov_in is None:
24
+ print('ファイルが読み込めません')
17
- import cv2
25
+ import sys
18
- import pyocr
19
- import pyocr.builders
20
- import numpy as np
21
- from matplotlib import pyplot as plt
22
- from PIL import Image, ImageFilter
23
- import time
26
+ sys.exit()
24
27
 
25
- import glob
28
+ cv2.imwrite(testfld + '/mov_in_gray.png', mov_in)
26
- import os
27
- import sys
29
+ cv2.waitKey(0)
28
- import win32com.client
29
- from datetime import datetime
30
30
 
31
+ #======================================
32
+ # 2値化
33
+ img_gry = (testfld + '/mov_in_gray.png')
34
+ org_img = cv2.imread(img_gry, 0)
31
35
 
32
- #===============================================================================
36
+ THRESHOLD = 215 # 閾値はNumpyで調べた
33
- testfld = 'C:/python/test/Cap'
37
+ MAXVALUE = 255 # 255 = white
34
38
 
35
- #===============================================================================
39
+ _, bin_cv2 = cv2.threshold(org_img, THRESHOLD, MAXVALUE, cv2.THRESH_BINARY_INV)
40
+ # [_INV]で背景白、黒文字にすることができる(Tesseractで読める絶対条件!)
36
41
 
37
- #-------------------------------------------------------------------------------
38
- if __name__ == '__main__':
42
+ bin_npy = np.zeros(org_img.shape, org_img.dtype)
43
+ bin_npy[np.where(org_img > THRESHOLD)] = MAXVALUE
39
44
 
40
- cv2.imwrite(testfld + '/binary_no' +str(picno)+ '.png', bin_cv2)
45
+ cv2.imwrite(testfld + '/binary_no' +str(picno)+ '.png', bin_cv2)
41
46
 
42
47
  #======================================
43
48
  # 文字認識
@@ -79,13 +84,4 @@
79
84
  print('----------------------------')
80
85
 
81
86
  text = [ev01, ev02, ev03, ev04, ev05]
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
87
  ```