Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-158
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-158
2022-158
Commits
e6340910
Commit
e6340910
authored
Sep 16, 2022
by
Weerasinghe D.N.H
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BACKEND :errors fixed in methods
parent
ed9ff9a6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
21 deletions
+33
-21
backend/app.py
backend/app.py
+1
-1
backend/database.db
backend/database.db
+0
-0
backend/routes/submission_routes.py
backend/routes/submission_routes.py
+3
-2
backend/services/class_model_detection_service.py
backend/services/class_model_detection_service.py
+29
-18
backend/submissions/class/research_classes-Page-1.jpg
backend/submissions/class/research_classes-Page-1.jpg
+0
-0
backend/tensorflow_models/class/label/label_map.pbtxt
backend/tensorflow_models/class/label/label_map.pbtxt
+0
-0
No files found.
backend/app.py
View file @
e6340910
...
...
@@ -55,7 +55,7 @@ def create_tables():
@
app
.
get
(
'/api/v1/'
)
def
index
():
async
def
index
():
return
'UML Diagram Plagiarism Detection Tool API'
...
...
backend/database.db
View file @
e6340910
No preview for this file type
backend/routes/submission_routes.py
View file @
e6340910
...
...
@@ -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
backend/services/class_model_detection_service.py
View file @
e6340910
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
,
im
g1_path
)
im
age_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
):
...
...
backend/submissions/class/research_classes-Page-1.jpg
0 → 100644
View file @
e6340910
69.5 KB
backend/tensorflow_models/class/label/label_map
.pbtxt
→
backend/tensorflow_models/class/label/label_map.pbtxt
View file @
e6340910
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment