Jamshaid89 commited on
Commit
1e1f35f
1 Parent(s): 7cf8e2a

Added initial open cv iamge editing

Browse files
Files changed (2) hide show
  1. app.py +20 -6
  2. requirements.txt +2 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import numpy as np
4
  from deepface import DeepFace
5
  from pymongo.mongo_client import MongoClient
 
6
 
7
  credentials = "jamshaid:jamshaid19gh"
8
 
@@ -89,8 +90,21 @@ def predict_image(image):
89
  print("5")
90
 
91
  identities.append({"name":name , "facial_area":target_embedding_obj["facial_area"]})
92
-
93
- return str(identities)
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
 
96
  # image_input = gr.inputs.Image(shape=(160,160))
@@ -118,8 +132,8 @@ interface1 = gr.Interface(
118
 
119
  # Create Gradio interfaces for image input and output
120
  image_input2 = gr.inputs.Image(shape=(None, None))
121
- # output_image = gr.outputs.Image(type="numpy")
122
- output_image = gr.outputs.Textbox()
123
 
124
  # Create the Gradio interface for image input and output
125
  interface2 = gr.Interface(
@@ -136,9 +150,9 @@ interface2 = gr.Interface(
136
  # interface.add_view(interface2, "Predict", "Get identity of person")
137
 
138
  gr.TabbedInterface(
139
- [interface1 , interface2],
140
  tab_names=["Predict Persons","Add new Person"]
141
- ).queue().launch( )
142
 
143
  # Launch the Gradio interface
144
  interface.launch()
 
3
  import numpy as np
4
  from deepface import DeepFace
5
  from pymongo.mongo_client import MongoClient
6
+ import cv2
7
 
8
  credentials = "jamshaid:jamshaid19gh"
9
 
 
90
  print("5")
91
 
92
  identities.append({"name":name , "facial_area":target_embedding_obj["facial_area"]})
93
+
94
+ for identity in identities:
95
+ # Draw the rectangle on the image
96
+ x = identity["facial_area"]["x"]
97
+ y = identity["facial_area"]["y"]
98
+ w = identity["facial_area"]["w"]
99
+ h = identity["facial_area"]["h"]
100
+ cv2.rectangle(image, (x,y), (x+w,y+h), (0, 0, 255), 2)
101
+
102
+ # Define the text position
103
+ text_position = (x, y+h+30)
104
+
105
+ # Add the text to the image
106
+ cv2.putText(image, identity["name"], text_position, cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255,0 ), 2)
107
+ return image
108
 
109
 
110
  # image_input = gr.inputs.Image(shape=(160,160))
 
132
 
133
  # Create Gradio interfaces for image input and output
134
  image_input2 = gr.inputs.Image(shape=(None, None))
135
+ output_image = gr.outputs.Image(type="numpy")
136
+ # output_image = gr.outputs.Textbox()
137
 
138
  # Create the Gradio interface for image input and output
139
  interface2 = gr.Interface(
 
150
  # interface.add_view(interface2, "Predict", "Get identity of person")
151
 
152
  gr.TabbedInterface(
153
+ [interface2 , interface1],
154
  tab_names=["Predict Persons","Add new Person"]
155
+ ).queue().launch()
156
 
157
  # Launch the Gradio interface
158
  interface.launch()
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  numpy
2
  deepface
3
- pymongo
 
 
1
  numpy
2
  deepface
3
+ pymongo
4
+ opencv-python