turhancan97 commited on
Commit
d61d710
·
1 Parent(s): 215c3f7

app deploy

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -96,7 +96,6 @@ path = [['image_0.jpg'], ['image_1.jpg'], ['image_2.jpg']]
96
  video_path = [['video.mp4']]
97
 
98
  def show_preds_image(image_path):
99
- global angle
100
  image = cv2.imread(image_path)
101
  #resize image (optional)
102
  img_res_toshow = cv2.resize(image, None, fx= 0.5, fy= 0.5, interpolation= cv2.INTER_LINEAR)
@@ -105,6 +104,7 @@ def show_preds_image(image_path):
105
  dim=(width,height)
106
 
107
  outputs = model.predict(source=img_res_toshow)
 
108
  for object in range(len(outputs[0].masks.masks)):
109
  #obtain BW image
110
  bw=(outputs[0].masks.masks[object].cpu().numpy() * 255).astype("uint8")
@@ -124,8 +124,12 @@ def show_preds_image(image_path):
124
  cv2.drawContours(img, contours, i, (0, 0, 255), 2)
125
 
126
  # Find the orientation of each shape
127
- angle = getOrientation(c, img)
128
-
 
 
 
 
129
  results = outputs[0].cpu().numpy()
130
  for i, det in enumerate(results.boxes.xyxy):
131
  cv2.rectangle(
@@ -136,13 +140,14 @@ def show_preds_image(image_path):
136
  thickness=2,
137
  lineType=cv2.LINE_AA
138
  )
139
- return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
140
 
141
  inputs_image = [
142
  gr.components.Image(type="filepath", label="Input Image"),
143
  ]
144
  outputs_image = [
145
  gr.components.Image(type="numpy", label="Output Image"),
 
146
  ]
147
  interface_image = gr.Interface(
148
  fn=show_preds_image,
@@ -153,7 +158,6 @@ interface_image = gr.Interface(
153
  cache_examples=False,
154
  )
155
 
156
-
157
  def show_preds_video(video_path):
158
  cap = cv2.VideoCapture(video_path)
159
  while(cap.isOpened()):
 
96
  video_path = [['video.mp4']]
97
 
98
  def show_preds_image(image_path):
 
99
  image = cv2.imread(image_path)
100
  #resize image (optional)
101
  img_res_toshow = cv2.resize(image, None, fx= 0.5, fy= 0.5, interpolation= cv2.INTER_LINEAR)
 
104
  dim=(width,height)
105
 
106
  outputs = model.predict(source=img_res_toshow)
107
+ angle_list = []
108
  for object in range(len(outputs[0].masks.masks)):
109
  #obtain BW image
110
  bw=(outputs[0].masks.masks[object].cpu().numpy() * 255).astype("uint8")
 
124
  cv2.drawContours(img, contours, i, (0, 0, 255), 2)
125
 
126
  # Find the orientation of each shape
127
+ angle_deg = getOrientation(c, img)
128
+ angle_list.append(angle_deg)
129
+ text = 'The orientation of the objects are: '
130
+ for angle in angle_list:
131
+ text += str(angle) + ' '
132
+ text += 'degrees'
133
  results = outputs[0].cpu().numpy()
134
  for i, det in enumerate(results.boxes.xyxy):
135
  cv2.rectangle(
 
140
  thickness=2,
141
  lineType=cv2.LINE_AA
142
  )
143
+ return cv2.cvtColor(img, cv2.COLOR_BGR2RGB), text
144
 
145
  inputs_image = [
146
  gr.components.Image(type="filepath", label="Input Image"),
147
  ]
148
  outputs_image = [
149
  gr.components.Image(type="numpy", label="Output Image"),
150
+ gr.outputs.Textbox(label="Orientation Angle")
151
  ]
152
  interface_image = gr.Interface(
153
  fn=show_preds_image,
 
158
  cache_examples=False,
159
  )
160
 
 
161
  def show_preds_video(video_path):
162
  cap = cv2.VideoCapture(video_path)
163
  while(cap.isOpened()):