tobby48 4 年前
父节点
当前提交
4e271ffe63

二进制
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/data/hello.mp3 查看文件


+ 17
- 0
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/imagesplit.py 查看文件

1
+from PIL import Image
2
+
3
+infile = "ja.PNG"
4
+chopsize = 300
5
+
6
+img = Image.open(infile)
7
+width, height = img.size
8
+
9
+# Save Chops of original image
10
+for x0 in range(0, width, chopsize):
11
+   for y0 in range(0, height, chopsize):
12
+      box = (x0, y0,
13
+             x0+chopsize if x0+chopsize <  width else  width - 1,
14
+             y0+chopsize if y0+chopsize < height else height - 1)
15
+      print('%s %s' % (infile, box))
16
+      img.crop(box).save('C:\\Users\\tobby48\\Desktop\\지문자\\zchop.%s.x%03d.y%03d.jpg' % (infile.replace('.jpg',''), x0, y0))
17
+    

+ 1
- 1
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/s1_image_to_text.py 查看文件

1
 import pytesseract
1
 import pytesseract
2
 pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract'
2
 pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract'
3
-print(pytesseract.image_to_string('data\\test4.PNG',lang='kor'))
3
+print(pytesseract.image_to_string('data\\test3.png',lang='kor'))

+ 1
- 1
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/s4_image_to_text_to_voice.py 查看文件

3
 import pytesseract
3
 import pytesseract
4
 
4
 
5
 pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract'
5
 pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract'
6
-text = pytesseract.image_to_string('data\\test1.PNG',lang='kor')
6
+text = pytesseract.image_to_string('data\\test2.PNG',lang='kor')
7
 print(text)
7
 print(text)
8
 tts = gTTS(text=text, lang='ko')
8
 tts = gTTS(text=text, lang='ko')
9
 tts.save("data\\hello.mp3")
9
 tts.save("data\\hello.mp3")

+ 1
- 1
src/main/python/kr/co/swh/lecture/opensource/ocr_tts/sspecial_image_to_text.py 查看文件

10
 cv2.imshow('Black white image', blackAndWhiteImage)
10
 cv2.imshow('Black white image', blackAndWhiteImage)
11
 cv2.imshow('Original image',originalImage)
11
 cv2.imshow('Original image',originalImage)
12
 cv2.imshow('Gray image', grayImage)
12
 cv2.imshow('Gray image', grayImage)
13
-# cv2.waitKey(0)
13
+cv2.waitKey(0)
14
 
14
 
15
 
15
 
16
 pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract'
16
 pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract'