def vector2pixel(self, vec):
     pixel = Pixel()
     cw = self.ci_.width
     ch = self.ci_.height
     pixel.u = cw * vec.x
     pixel.v = ch * vec.y
     if (pixel.u < 0): pixel.u = 0
     if (pixel.u > cw - 1): pixel.u = cw - 1
     if (pixel.v < 0): pixel.v = 0
     if (pixel.v > ch - 1): pixel.v = 0
     return pixel
    def ground2pixel(self, point):
        ground_point = np.array([point.x, point.y, 1.0])
        image_point = np.dot(self.Hinv, ground_point)
        image_point = image_point / image_point[2]

        pixel = Pixel()
        if not self.rectified_input:
            distorted_pixel = self.pcm_.project3dToPixel(image_point)
            pixel.u = distorted_pixel[0]
            pixel.v = distorted_pixel[1]
        else:
            pixel.u = image_point[0]
            pixel.v = image_point[1]
    def ground2pixel(self, point):
        # TODO check whether z=0 or z=1.
        # I think z==1 (jmichaux)
        ground_point = np.array([point.x, point.y, 1.0])
        image_point = self.Hinv * ground_point
        image_point = np.abs(image_point / image_point[2])

        pixel = Pixel()
        if not self.rectified_input:
            distorted_pixel = self.pcm_.project3dToPixel(image_point)
            pixel.u = distorted_pixel[0]
            pixel.v = distorted_pixel[1]
        else:
            pixel.u = image_point[0]
            pixel.v = image_point[1]
    def ground2pixel(self, point):
        if point.z != 0:
            msg = 'This method assumes that the point is a ground point (z=0). '
            msg += 'However, the point is (%s,%s,%s)' % (point.x, point.y,
                                                         point.z)
            raise ValueError(msg)

        ground_point = np.array([point.x, point.y, 1.0])
        # An applied mathematician would cry for this
        #    image_point = np.dot(self.Hinv, ground_point)
        # A better way:
        image_point = np.linalg.solve(self.H, ground_point)

        image_point = image_point / image_point[2]

        pixel = Pixel()
        #         if not self.rectified_input:
        #             dtu.logger.debug('project3dToPixel')
        #             distorted_pixel = self.pcm.project3dToPixel(image_point)
        #             pixel.u = distorted_pixel[0]
        #             pixel.v = distorted_pixel[1]
        #         else:
        pixel.u = image_point[0]
        pixel.v = image_point[1]

        return pixel
 def vector2pixel(self, vec):
     """ Converts a [0,1]*[0,1] representation to [0, W]x[0, H]. """
     pixel = Pixel()
     cw = self.ci.width
     ch = self.ci.height
     pixel.u = cw * vec.x
     pixel.v = ch * vec.y
     return pixel