Skip to content

Commit

Permalink
image detect stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
maeriil committed Sep 29, 2023
1 parent e4eeba3 commit e9d9685
Show file tree
Hide file tree
Showing 38 changed files with 180 additions and 229 deletions.
Binary file added backend/Screenshot 2023-09-29 133341.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/__pycache__/main.cpython-311.pyc
Binary file not shown.
Binary file removed backend/backend/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed backend/backend/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file removed backend/backend/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file removed backend/backend/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.
16 changes: 0 additions & 16 deletions backend/backend/asgi.py

This file was deleted.

123 changes: 0 additions & 123 deletions backend/backend/settings.py

This file was deleted.

23 changes: 0 additions & 23 deletions backend/backend/urls.py

This file was deleted.

16 changes: 0 additions & 16 deletions backend/backend/wsgi.py

This file was deleted.

Binary file added backend/char1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/char2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/char3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/char4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/char5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/char6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/col1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file removed backend/db.sqlite3
Empty file.
Binary file added backend/french.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/japanese.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/jp-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/jp-text2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# from flask import Flask

# app = Flask(__name__)

# @app.route("/")
# def hello_world():
# return "<p>asdasd!</p>"


#: flask to get data from frontend (assume we have data for now) (last thing we build in backend)
#: OCR or Pytesseract for extracting text from image
#: Pillow library to edit on the images
#: googletrans to translate the text from language 1 to English
#:

import cv2
import pytesseract
from googletrans import Translator
from manga_ocr import MangaOcr
from PIL import Image

MOCKIMAGEPATH = 'japanese.png'
mockImage = cv2.imread(MOCKIMAGEPATH)
pytesseract_config = r'--oem 3 --psm 5 -l jpn_vert'

grayscale = cv2.cvtColor(mockImage, cv2.COLOR_BGR2GRAY) # convert image to grayscale
blur = cv2.GaussianBlur(grayscale, (9, 9), 0)
# threshold = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

# Attempt to remove noise from image
# kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
# opening = cv2.morphologyEx(threshold, cv2.MORPH_OPEN, kernel, iterations=1)
# invert = 255 - opening
img = cv2.imread(MOCKIMAGEPATH)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Performing OTSU threshold
ret, thresh1 = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU | cv2.THRESH_BINARY_INV)

# Specify structure shape and kernel size.
# Kernel size increases or decreases the area
# of the rectangle to be detected.
# A smaller value like (10, 10) will detect
# each word instead of a sentence.
rect_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (18, 18))

# Applying dilation on the threshold image
dilation = cv2.dilate(thresh1, rect_kernel, iterations = 1)
cv2.imshow('dilation ', dilation)

# Finding contours
contours, hierarchy = cv2.findContours(dilation, cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_NONE)

# Creating a copy of image
im2 = img.copy()

# A text file is created and flushed

# Looping through the identified contours
# Then rectangular part is cropped and passed on
# to pytesseract for extracting text from it
# Extracted text is then written into the text file
for cnt in contours:
x, y, w, h = cv2.boundingRect(cnt)

# Drawing a rectangle on copied image
rect = cv2.rectangle(im2, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow('rectangle is ', rect)

# Cropping the text block for giving input to OCR
cropped = im2[y:y + h, x:x + w]

# Open the file in append mode
file = open("recognized.txt", "a")

# Apply OCR on the cropped image
text = pytesseract.image_to_string(cropped)
print(text)

cv2.waitKey()
# jp_text = pytesseract.image_to_string(invert, config=pytesseract_config)
# print(jp_text)

# cv2.imshow('mockimage', mockImage)
# cv2.imshow('blur', blur)
# cv2.imshow('threshold', threshold)
# cv2.imshow('opening', opening)
# cv2.imshow('invert', invert)
# cv2.waitKey()

# translator = Translator()
# translatedText = translator.translate(jp_text, dest="en", src="ja")

# print('[translated]: ', translatedText.text)
22 changes: 0 additions & 22 deletions backend/manage.py

This file was deleted.

File renamed without changes.
8 changes: 7 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
flake8
flake8
Flask
pytesseract
numpy
googletrans==4.0.0-rc1
opencv-python
manga-ocr
78 changes: 78 additions & 0 deletions backend/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
== DEFAULT ==

陣夫団…

3J心惨枯コピ

的S刀は8條パ避
pn)っっべ直玩
所0しWつろう@…

== PSM 5 ==
it ョ
アク 駐 Je転つじ 垂
4 。 六は衝
5 病生4にだだなくり月還=
世- 的0し民つっ6G… ミ ミ
ラー



== JP text ==
弄人団…

32J心羽村つレ

的刀は6條で避

Jpいひいう)っうべ相対

拘でしつう@…
2

== JP text ==
則失団…
2JD尺本つレ
的や刀け6條で
Jpいう)っつうっうべで直人
拘でしつう@…



冊挫団…
2J①尺村つビレ
SS怠け6條%い
Jpいつつべ直志
拘でし8H6つろう@…

9

Gaussian kernel = 5x5

陣老団…
2J①尺寺つビレ
的や台中6條る
jpいう)うつうべ牛装
的しWOつっ@G…


Gaussian kernel = 7x7

陣挫団…
2JQ尺相つレ
Sや刀け16條%
おpいつっうべ直人
的でしレH6つうG…


Gaussian kernel = 9x9

冊挫団…
32J心尺相つレ
的や刀はで條へ
Jpいうつつうべ直乱
的でしレH6つっう@…
Empty file removed backend/translator/__init__.py
Empty file.
Binary file removed backend/translator/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed backend/translator/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file removed backend/translator/__pycache__/views.cpython-311.pyc
Binary file not shown.
3 changes: 0 additions & 3 deletions backend/translator/admin.py

This file was deleted.

Loading

0 comments on commit e9d9685

Please sign in to comment.