Beispiel #1
0
    def loadData(self):
        Palette = ColorBlind_10
        NMFiles = self.getFileNames(self.Args.nocs_maps)
        ColorFiles = [None] * len(NMFiles)
        PoseFiles = [None] * len(NMFiles)
        if self.Args.colors is not None:
            ColorFiles = self.getFileNames(self.Args.colors)
        if self.Args.poses is not None:
            PoseFiles = self.getFileNames(self.Args.poses)

        for (NMF, Color, CF, PF) in zip(NMFiles, Palette.colors, ColorFiles, PoseFiles):
            NOCSMap = cv2.imread(NMF, -1)
            NOCSMap = NOCSMap[:, :, :3] # Ignore alpha if present
            NOCSMap = cv2.cvtColor(NOCSMap, cv2.COLOR_BGR2RGB) # IMPORTANT: OpenCV loads as BGR, so convert to RGB
            if self.Intrinsics is None:
                self.ImageSize = (NOCSMap.shape[1], NOCSMap.shape[0])
            else:
                NOCSMap = self.resizeAndPad(NOCSMap)
            CFIm = None
            if CF is not None:
                CFIm = cv2.imread(CF)
                CFIm = cv2.cvtColor(CFIm, cv2.COLOR_BGR2RGB) # IMPORTANT: OpenCV loads as BGR, so convert to RGB
                if CFIm.shape != NOCSMap.shape: # Re-size only if not the same size as NOCSMap
                    CFIm = cv2.resize(CFIm, (NOCSMap.shape[1], NOCSMap.shape[0]), interpolation=cv2.INTER_CUBIC) # Ok to use cubic interpolation for RGB
            NOCS = ds.NOCSMap(NOCSMap, RGB=CFIm)
            self.NOCSMaps.append(NOCSMap)
            self.NOCS.append(NOCS)

            if self.Args.no_pose == False:
                _, K, R, C, Flip = self.estimateCameraPoseFromNM(NOCSMap, NOCS, N=self.Args.num_points, Intrinsics=self.Intrinsics) # The rotation and translation are about the NOCS origin
                self.CamIntrinsics.append(K)
                self.CamRots.append(R)
                self.CamPos.append(C)
                self.CamFlip.append(Flip)
                self.Cameras.append(ds.Camera(ds.CameraExtrinsics(self.CamRots[-1], self.CamPos[-1]), ds.CameraIntrinsics(self.CamIntrinsics[-1])))

                if PF is not None:
                    with open(PF) as f:
                        data = json.load(f)
                        # Loading convention: Flip sign of x postiion, flip signs of quaternion z, w
                        P = np.array([data['position']['x'], data['position']['y'], data['position']['z']])
                        Quat = np.array([data['rotation']['w'], data['rotation']['x'], data['rotation']['y'], data['rotation']['z']]) # NOTE: order is w, x, y, z
                        # Cajole transforms to work
                        P[0] *= -1
                        P += 0.5
                        Quat = np.array([Quat[0], Quat[1], -Quat[2], -Quat[3]])

                        self.PosesPos.append(P)
                        R = quaternions.quat2mat(Quat).T
                        self.PosesRots.append(R)
                else:
                    self.PosesPos.append(None)
                    self.PosesRots.append(None)

        self.nNM = len(NMFiles)
        self.activeNMIdx = self.nNM # len(NMFiles) will show all
Beispiel #2
0
    def deserialize(self, InJSONFile):
        with open(InJSONFile) as f:
            data = json.load(f)
            # Loading convention: Flip sign of x position, flip signs of quaternion z, w
            P = np.array([data['position']['x'], data['position']['y'], data['position']['z']])
            Quat = np.array([data['rotation']['w'], data['rotation']['x'], data['rotation']['y'],
                             data['rotation']['z']])  # NOTE: order is w, x, y, z
            # Cajole transforms to work
            P[0] *= -1
            # P += 0.5 # Hack to offset to NOCS center
            Quat = np.array([Quat[0], Quat[1], -Quat[2], -Quat[3]])

            self.Translation = P
            R = quaternions.quat2mat(Quat).T
            self.Rotation = R