gelsightinc / gsrobotics

GelSight SDK for robotic sensors
GNU General Public License v3.0
80 stars 24 forks source link

resize_crop_mini taking up CPUs #13

Closed duyipai closed 1 year ago

duyipai commented 1 year ago

The current implementation of the function resize_crop_mini in gsdevice.py seems to be redundant and it is taking up all the CPUs on my PC. I tried to modify it to only do resize once, which reduced the CPU load significantly. Would you consider to merge it?

def resize_crop_mini(img, imgw, imgh):
  border_size_x, border_size_y = int(img.shape[0] * (1 / 7)), int(np.floor(img.shape[1] * (1 / 7)))  # remove 1/7th of border from each size
  img = img[border_size_x:img.shape[0] - border_size_x, border_size_y:img.shape[1] - border_size_y]
  img = cv2.resize(img, (imgw, imgh), interpolation = cv2.INTER_AREA) # final resize for 3d
  return img
debrashure commented 1 year ago

@duyipai

Your feedback is much appreciated. The resize_crop_mini has been updated so that resize is only done once.

`

# remove 1/7th of border from each size
border_size_x, border_size_y = int(img.shape[0] * (1 / 7)), int(np.floor(img.shape[1] * (1 / 7)))

# keep the ratio the same as the original image size
img = img[border_size_x+2:img.shape[0] - border_size_x, border_size_y:img.shape[1] - border_size_y]

# final resize for 3d
img = cv2.resize(img, (imgw, imgh))

return img

`