mpskex / Convolutional-Pose-Machine-tf

Convolutional Pose Machine tensorflow implementation
GNU Lesser General Public License v3.0
71 stars 18 forks source link

the problem in the code about crop and padding #3

Closed do-oo closed 6 years ago

do-oo commented 6 years ago

def _crop_data(self, height, width, box, joints, boxp=0.05): """ Automatically returns a padding vector and a bounding box given the size of the image and a list of joints. Args: height : Original Height width : Original Width box : Bounding Box joints : Array of joints boxp : Box percentage (Use 20% to get a good bounding box) """ padding = [[0, 0], [0, 0], [0, 0]] j = np.copy(joints) if box[0:2] == [-1, -1]: j[joints == -1] = 1e5 box[0], box[1] = min(j[:, 0]), min(j[:, 1]) crop_box = [box[0] - int(boxp (box[2] - box[0])), box[1] - int(boxp (box[3] - box[1])), box[2] + int(boxp (box[2] - box[0])), box[3] + int(boxp (box[3] - box[1]))] if crop_box[0] < 0: crop_box[0] = 0 if crop_box[1] < 0: crop_box[1] = 0 if crop_box[2] > width - 1: crop_box[2] = width - 1 if crop_box[3] > height - 1: crop_box[3] = height - 1 new_h = int(crop_box[3] - crop_box[1]) new_w = int(crop_box[2] - crop_box[0]) crop_box = [crop_box[0] + new_w // 2, crop_box[1] + new_h // 2, new_w, new_h] if new_h > new_w: bounds = (crop_box[0] - new_h // 2, crop_box[0] + new_h // 2) if bounds[0] < 0: padding[1][0] = abs(bounds[0]) if bounds[1] > width - 1: padding[1][1] = abs(width - bounds[1]) elif new_h < new_w: bounds = (crop_box[1] - new_w // 2, crop_box[1] + new_w // 2) if bounds[0] < 0: padding[0][0] = abs(bounds[0]) if bounds[1] > width - 1: padding[0][1] = abs(height - bounds[1]) crop_box[0] += padding[1][0] crop_box[1] += padding[0][0] return padding, crop_box

你这里是 操作的padding[1],padding[0], 最后使用了 np.pad(padding),但是 np.pad 中的pad 参数 第一个是用来填充的数字,padding[1], padding[2]才是用来存储应该pad的最小最大扩展长度

mpskex commented 6 years ago

我建议您可以先参考一下numpy的官方文档。这里就是[(before, after)*dimension]的padding参数。我能确认这里的操作没有问题。感谢提交Issue。

mpskex commented 6 years ago

问题解决