turhancan97 commited on
Commit
829e78c
1 Parent(s): ab75898

fix video issue

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -70,7 +70,7 @@ file_urls = [
70
  'https://github.com/lucarei/orientation-detection-robotic-grasping/assets/22428774/cefd9731-c57c-428b-b401-fd54a8bd0a95',
71
  'https://github.com/lucarei/orientation-detection-robotic-grasping/assets/22428774/acbad76a-33f9-4028-b012-4ece5998c272',
72
  'https://github.com/lucarei/orientation-detection-robotic-grasping/assets/22428774/ce8a0fb9-99ea-4952-bcc4-3afa023066d9',
73
- 'https://www.dropbox.com/scl/fi/z706oqbexdbk3gjvlzzjo/video-2160p.mp4?rlkey=7s3cx7tiwitwuad4k34f6jo9g&dl=0'
74
  ]
75
 
76
  def download_file(url, save_name):
@@ -164,10 +164,18 @@ def show_preds_video(video_path):
164
  ret, frame = cap.read()
165
  if ret:
166
  frame_copy = frame.copy()
 
 
 
 
 
167
  outputs = model.predict(source=frame)
168
  for object in range(len(outputs[0].masks.masks)):
169
  #obtain BW image
170
  bw=(outputs[0].masks.masks[object].cpu().numpy() * 255).astype("uint8")
 
 
 
171
  contours, _ = cv2.findContours(bw, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
172
  for i, c in enumerate(contours):
173
  # Calculate the area of each contour
@@ -178,10 +186,11 @@ def show_preds_video(video_path):
178
  continue
179
 
180
  # Draw each contour only for visualisation purposes
181
- cv2.drawContours(frame_copy, contours, i, (0, 0, 255), 2)
182
 
183
  # Find the orientation of each shape
184
- angle_deg = getOrientation(c, frame_copy)
 
185
  results = outputs[0].cpu().numpy()
186
  for i, det in enumerate(results.boxes.xyxy):
187
  cv2.rectangle(
 
70
  'https://github.com/lucarei/orientation-detection-robotic-grasping/assets/22428774/cefd9731-c57c-428b-b401-fd54a8bd0a95',
71
  'https://github.com/lucarei/orientation-detection-robotic-grasping/assets/22428774/acbad76a-33f9-4028-b012-4ece5998c272',
72
  'https://github.com/lucarei/orientation-detection-robotic-grasping/assets/22428774/ce8a0fb9-99ea-4952-bcc4-3afa023066d9',
73
+ 'https://www.dropbox.com/s/7sjfwncffg8xej2/video_7.mp4?dl=1'
74
  ]
75
 
76
  def download_file(url, save_name):
 
164
  ret, frame = cap.read()
165
  if ret:
166
  frame_copy = frame.copy()
167
+ #resize image (optional)
168
+ img_res_toshow = cv2.resize(frame_copy, None, fx= 0.5, fy= 0.5, interpolation= cv2.INTER_LINEAR)
169
+ height=img_res_toshow.shape[0]
170
+ width=img_res_toshow.shape[1]
171
+ dim=(width,height)
172
  outputs = model.predict(source=frame)
173
  for object in range(len(outputs[0].masks.masks)):
174
  #obtain BW image
175
  bw=(outputs[0].masks.masks[object].cpu().numpy() * 255).astype("uint8")
176
+ #BW image with same dimention of initial image
177
+ bw=cv2.resize(bw, dim, interpolation = cv2.INTER_AREA)
178
+ img=img_res_toshow
179
  contours, _ = cv2.findContours(bw, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
180
  for i, c in enumerate(contours):
181
  # Calculate the area of each contour
 
186
  continue
187
 
188
  # Draw each contour only for visualisation purposes
189
+ cv2.drawContours(img, contours, i, (0, 0, 255), 2)
190
 
191
  # Find the orientation of each shape
192
+ angle_deg = getOrientation(c, img)
193
+
194
  results = outputs[0].cpu().numpy()
195
  for i, det in enumerate(results.boxes.xyxy):
196
  cv2.rectangle(