Commit e6340910 authored by Weerasinghe D.N.H's avatar Weerasinghe D.N.H

BACKEND :errors fixed in methods

parent ed9ff9a6
......@@ -55,7 +55,7 @@ def create_tables():
@app.get('/api/v1/')
def index():
async def index():
return 'UML Diagram Plagiarism Detection Tool API'
......
No preview for this file type
......@@ -14,7 +14,7 @@ submission = Blueprint('submissions', __name__, url_prefix='/api/v1/submissions'
@submission.post('/upload')
@jwt_required()
def upload_submission():
async def upload_submission():
user_id = get_jwt_identity()
image = request.files['file']
......@@ -29,9 +29,10 @@ def upload_submission():
use_case_obj = save_submission(assignment_id, image, submission_type, comment, user_id)
model_object_detection(image.filename, use_case_obj.id)
return jsonify({'filename': image.filename}), HTTP_200_OK
elif submission_type == 'class':
class_obj = save_submission(assignment_id, image, submission_type, comment, user_id)
component_separation(image.filename, class_obj.id)
await component_separation(image.filename, class_obj.id)
return jsonify({'id': str(class_obj.id)}), HTTP_200_OK
else:
return jsonify({'err': 'invalid request '}), HTTP_400_BAD_REQUEST
import operator
import os
import re
import cv2
......@@ -12,30 +13,37 @@ import app
import tensorflow as tf
import spacy
from config.database import db
from models.method import Method
ts.pytesseract.tesseract_cmd = r'C:\Users\DELL\AppData\Local\Programs\Tesseract-OCR\tesseract.exe'
def component_separation(filename, class_comp_id):
mdl1_path = app.CLASS_SAVED_MODEL_PATH
lbl1_path = app.CLASS_SAVED_LABEL_PATH
img1_path = app.SUBMISSION_PATH_CLASS + '/' + filename
image_nparray = np.array(Image.open(img1_path))
print(img1_path)
boxes, num_entities, accurate_indexes, num_entities, category_index, class_id = class_object_detection(mdl1_path,
lbl1_path,
img1_path)
image_nparray)
# Convert the class id in their name
if num_entities > 0:
for index in range(0, len(accurate_indexes)):
if category_index[class_id[index]]['name'] == 'class' or category_index[class_id]['name'] == 'interface':
class_details_detection(filename, boxes, index, class_comp_id)
if category_index[class_id[index]]['name'] == 'class':
print(filename)
_image = crop_image_(image_nparray, boxes, index)
class_details_detection(_image, class_comp_id)
def class_object_detection(model_path, label_path, image_path):
def class_object_detection(model_path, label_path, image_nparray):
detect_fn = tf.saved_model.load(model_path)
category_index = label_map_util.create_category_index_from_labelmap(label_path, use_display_name=True)
image_np = np.array(Image.open(image_path))
image_np = image_nparray
input_tensor = tf.convert_to_tensor(image_np)
input_tensor = input_tensor[tf.newaxis, ...]
......@@ -57,31 +65,34 @@ def class_object_detection(model_path, label_path, image_path):
return boxes, num_entities, accurate_indexes, num_entities, category_index, class_id
def class_details_detection(filename, boxes, index, class_comp_id):
_image = crop_and_image_resolution(filename, boxes, index)
cv2.imwrite(app.SUBMISSION_PATH_CLASS + '/' + "class" + str(index), _image)
def class_details_detection(_image, class_comp_id):
retval = os.getcwd()
print("Current working directory %s" % retval)
# _image.save(os.path.join(app.SUBMISSION_PATH_CLASS, "class" + str(index) + ".jpg"))
mdl2_path = app.CLASS_COMP_SAVED_MODEL_PATH
lbl2_path = app.CLASS_COMP_SAVED_LABEL_PATH
img2_path = app.SUBMISSION_PATH_CLASS + '/' + "class" + str(index)
# img2_path = app.SUBMISSION_PATH_CLASS + '/' + "class" + str(index)
boxes_class, num_entities, accurate_indexes, num_entities, category_index, class_id = class_object_detection(
mdl2_path, lbl2_path, img2_path)
mdl2_path, lbl2_path, _image)
if num_entities > 1:
for j in range(0, len(accurate_indexes)):
if category_index[class_id[j]]['name'] == 'class_attributes':
class_attributes = crop_and_image_resolution(img2_path, boxes_class, j)
class_attributes = crop_image_(_image, boxes_class, j)
text = text_extraction(class_attributes)
print(text)
save_attribute_method(text, 'attribute')
elif category_index[class_id[j]]['name'] == 'class_methods':
class_methods = crop_and_image_resolution(img2_path, boxes_class, j)
class_methods = crop_image_(_image, boxes_class, j)
text = text_extraction(class_methods)
print(text)
save_attribute_method(text, 'method')
# class name detection and save the class object
def crop_and_image_resolution(path, boxes, index):
image = cv2.imread(path)
def crop_image_(image, boxes, index):
# image = cv2.imread(path)
height, width, c = image.shape
# crop box format: xmin, ymin, xmax, ymax
ymin = boxes[index][0] * height
......@@ -90,10 +101,10 @@ def crop_and_image_resolution(path, boxes, index):
xmax = boxes[index][3] * width
cropped_image = image[int(ymin):int(ymax), int(xmin):int(xmax)]
image = cv2.cvtColor(cropped_image, cv2.COLOR_BGR2GRAY)
image = cv2.resize(image, (800, 500))
# image = cv2.cvtColor(cropped_image, cv2.COLOR_BGR2GRAY)
# image = cv2.resize(image, (800, 500))
return image
return cropped_image
def text_extraction(image):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment