コード例 #1
0
 def split_data(self):
     path = self.anon_path
     root = self.root
     save_path_dot = self.dot_path
     save_path_box = self.box_path
     Data = jr.read_all(path)
     index = 0
     if not os.path.exists(save_path_box):
         os.mkdir(save_path_box)
     else:
         pass
     if not os.path.exists(save_path_dot):
         os.mkdir(save_path_dot)
     else:
         pass
     for d in Data:
         img_path = root + d['name'].split('/')[2]
         print(d['name'])
         img = io.imread(img_path)
         s_path = ''
         if d['type'] == 'dot':
             s_path = save_path_dot + d['name'].split('/')[2]
         elif d['type'] == 'bbox':
             s_path = save_path_box + d['name'].split('/')[2]
         else:
             print("********************error*******************")
         io.imsave(s_path, img)
         index += 1
コード例 #2
0
    def show_point(self):
        idl = [54, 517, 2625, 1070, 1983, 2852, 2237, 222, 211, 2015]
        root = '/media/gzs/baidu_star_2018/image/stage2/'
        path = self.anon_path  #'/media/gzs/baidu_star_2018/annotation/annotation_train_stage1.json'
        data = jr.read(path)  #keys  :   points   name   type
        length = len(data)
        plt.ioff()
        for i in range(0, length):
            iid = data[i]['id']

            if iid in idl:
                continue
            else:
                pass
#            print(i)
            points = np.array(data[i]['points'])
            length = points.shape[0]
            type_t = data[i]['type']
            name = data[i]['name']  #.split('.')[0]+'.jpg'
            is_show = False

            for nnn in cls.read23():
                if str(name) == str(nnn[0]):
                    is_show = True
                    break
                else:
                    pass

            if is_show == True:
                pass
            else:
                continue

            if type_t == 'dot':
                img_path = root + "dot/" + name
            else:
                img_path = root + "box/" + name
            image = cv2.imread(img_path, 0)
            plt.close('all')
            plt.figure(1)
            plt.imshow(image, cmap=plt.cm.gray)
            if type_t == 'dot':
                plt.plot(points[:, 0], points[:, 1], 'ro')

            elif type_t == 'bbox':
                print('ignore : ' +
                      str(len(data[i]['ignore_region'])))  #ignore_region
                plt.plot(points[:, 0], points[:, 1], 'ro')
                currentAxis = plt.gca()
                for point in points:
                    rect = patches.Rectangle((point[0], point[1]),
                                             point[2],
                                             point[3],
                                             linewidth=1,
                                             edgecolor='r',
                                             facecolor='none')
                    currentAxis.add_patch(rect)
            plt.title("type : " + str(type_t) + "  id :" + str(data[i]['id']) +
                      " len : " + str(len(points)))
            plt.show()
コード例 #3
0
 def get_anon_dot(self):
     path = self.anon_path  #'/media/gzs/baidu_star_2018/annotation/annotation_train_stage1.json'
     Data = jr.read(path)
     rst = []
     for d in Data:
         if d['type'] == 'dot':
             rst.append(d)
         else:
             pass
     return rst
コード例 #4
0
    def __init__(self,json_path1,json_path2):
#        json_path1 = "/media/gzs/T/gzs/baidu_star_2018_test_stage1/baidu_star_2018/annotation/annotation_train_stage1.json"
#        json_path = "/media/gzs/T/gzs/baidu_star_2018_test_stage1/baidu_star_2018/annotation/annotation_train_stage2.json"
        annotations = jr.read_all(json_path2)
        annotations1 = jr.read_all(json_path1)
        name_arr = []
        ignore_arr = []
        typ_arr = []
        id_arr = []
        stage_arr = []
        for anon in annotations:
            name = anon['name'].strip().split('/')[-1]
            name_arr.append(name)
            ignore_region = anon['ignore_region']
            ignore_arr.append(ignore_region)
            ttype = anon['type']
            typ_arr.append(ttype)
            iid = anon['id']
            id_arr.append(iid)
            stage_arr.append("stage2")
        for anon in annotations1:
            ttype = anon['type']#if the type is dot .will be contain in train setting
            if ttype == 'dot':
                name = anon['name'].strip().split('/')[-1]
                name_arr.append(name)
                ignore_region = anon['ignore_region']
                ignore_arr.append(ignore_region)
                typ_arr.append(ttype)
                iid = anon['id']
                id_arr.append(iid)
                stage_arr.append("stage1")
            else:
                pass
        pd_name = pd.Series(name_arr)
        pd_ignore = pd.Series(ignore_arr)
        pd_type = pd.Series(typ_arr)
        pd_id = pd.Series(id_arr)
        stage = pd.Series(stage_arr)
        self.pd_DataFrame = pd.DataFrame({"name":pd_name,"ignore":pd_ignore,"type":pd_type,"id":pd_id,"stage":stage})
        self.test_datas = []
        self.train_datas = []
コード例 #5
0
    def removemask(self):
        path = self.anon_path  #'/media/gzs/baidu_star_2018/annotation/annotation_train_stage1.json'
        root = self.root  #'/media/gzs/baidu_star_2018/image/'
        save_path_dot = self.dot_path  #'/media/gzs/baidu_star_2018/image/stage1/dot/'
        save_path_box = self.box_path  #'/media/gzs/baidu_star_2018/image/stage1/box/'
        #    path = '/media/gzs/baidu_star_2018_test_stage1/baidu_star_2018/annotation/annotation_test_stage1.json'
        Data = jr.read_all(path)
        index = 0
        if not os.path.exists(save_path_box):
            os.mkdir(save_path_box)
        else:
            pass
        if not os.path.exists(save_path_dot):
            os.mkdir(save_path_dot)
        else:
            pass
        for d in Data:
            if len(d['ignore_region']) > 0:
                img_path = root + d['name'].split('/')[2]
                img = io.imread(img_path)
                ignore = d['ignore_region']
                print(d['name'])
                Y = []
                X = []
                for p in ignore[0]:
                    Y.append(p['y'])
                    X.append(p['x'])

                rr, cc = draw.polygon(np.array(Y), np.array(X))
                draw.set_color(img, [rr, cc], [255, 255, 255])  #[255,255,255]
                s_path = ''
                if d['type'] == 'dot':
                    s_path = save_path_dot + d['name'].split('/')[2]
                elif d['type'] == 'bbox':
                    print("***********************bbox***********************")
                    s_path = save_path_box + d['name'].split('/')[2]
                else:
                    print("********************error*******************")
                io.imsave(s_path, img)
            else:
                img_path = root + d['name'].split('/')[2]
                print(d['name'])
                img = io.imread(img_path)
                s_path = ''
                if d['type'] == 'dot':
                    s_path = save_path_dot + d['name'].split('/')[2]
                elif d['type'] == 'bbox':
                    s_path = save_path_box + d['name'].split('/')[2]
                else:
                    print("********************error*******************")
                io.imsave(s_path, img)
            index += 1
コード例 #6
0
    def CleaningData(
            self):  #root='/media/gzs/baidu_star_2018/image/stage1/box/'
        path = self.anon_path  #anon_path
        data = jr.read(path)
        rst = []

        for d in data:
            type_t = d['type']
            if type_t == 'dot':
                continue
            else:
                name = d['name']
                is_show = False
                for nnn in cls.read23():
                    if str(name) == str(nnn[0]):
                        is_show = True
                        break
                    else:
                        pass
                if is_show == True:
                    pass
                else:
                    continue
                path = self.box_path + d['name']
                image = cv2.imread(path, 0)

                h = image.shape[0]
                w = image.shape[1]
                #                print("o_w : "+str(w)+"  o_h : "+str(h))
                points_t = d['points']
                #                print(len(points_t))
                #                print(points_t)
                points, mask_points = self.Cleaning_points(w, h, points_t)

                if len(points) == 0:
                    tcl = {
                        'name': d['name'],
                        'points': points_t,
                        'mask': mask_points,
                        'id': d['id']
                    }
                else:
                    tcl = {
                        'name': d['name'],
                        'points': points,
                        'mask': mask_points,
                        'id': d['id']
                    }
                rst.append(tcl)
        return rst
コード例 #7
0
    def show_wh(self):
        _anon_path = self.anon_path
        #        _root = self.root
        _box_path = self.box_path
        _dot_path = self.dot_path
        data = jr.read(_anon_path)
        for d in data:
            name = d['name']
            dtype = d['type']
            #            points = d['points']
            if 'dot' == dtype:
                img_path = _dot_path + name
            else:
                img_path = _box_path + name
            image = cv2.imread(img_path)
            w = image.shape[1]
            h = image.shape[0]

            print("w : " + str(w) + "  h : " + str(h))
コード例 #8
0
    def argument_data(self):
        _anon_path = self.anon_path
        #        _root = self.root
        _box_img_path = "/media/gzs/baidu_star_2018/image/stage2/fixed_data/datas/box/train/"
        _box_den_path = "/media/gzs/baidu_star_2018/image/stage2/fixed_data/datas/box/train_den/"

        _dot_img_path = "/media/gzs/baidu_star_2018/image/stage1/fixed_datas/datas/dot/train/"
        _dot_den_path = "/media/gzs/baidu_star_2018/image/stage1/fixed_datas/datas/dot/train_den/"

        save_image_path = "/media/gzs/baidu_star_2018/image/stage2/fixed_data/datas/image/"
        save_den_path = "/media/gzs/baidu_star_2018/image/stage2/fixed_data/datas/den/"

        data = jr.read(_anon_path)
        for d in data:
            name = d['name']
            dtype = d['type']
            points = d['points']
            if 'dot' == dtype:
                img_path = _dot_img_path + name
                den_path = _dot_den_path + name.split('.')[0] + ".csv"
            elif 'bbox' == dtype:
                continue
#                img_path = _box_img_path + name
#                den_path = _box_den_path + name.split('.')[0]+".csv"
            image = cv2.imread(img_path)
            density = pd.read_csv(den_path, sep=',', header=None).values
            #            print(image.shape)
            #            print(density.shape)
            #            print(density)
            #            print(density[np.where(density>0)])
            #            exit()
            plt.figure(0)
            plt.subplot(121)
            plt.imshow(image, cmap=plt.cm.gray)
            plt.subplot(122)
            plt.imshow(density)
            plt.title("name : " + str(sum(sum(density))))
            plt.show()
コード例 #9
0
 def show_test(self):
     path = '/media/gzs/baidu_star_2018_test_stage2/baidu_star_2018/annotation/annotation_test_stage2.json'
     Data = jr.read_all(path)
     for d in Data:
         print(d['ignore_region'])
コード例 #10
0
ファイル: test.py プロジェクト: liyaoshun/CrowdCountingPY
def get_test_path():
    path = '/media/gzs/baidu_star_2018_test_stage2/baidu_star_2018/annotation/annotation_test_stage2.json'
    annotations = jr.read_all(path)
    #    print(len(annotations))
    #    exit()
    return annotations