(self, com=None, size=(250, 250, 250), dsize=(128, 128), docom=False)
return ret, numpy.dot(off, numpy.dot(scale, trans)), com
Crop area of hand in 3D volumina, scales inverse to the distance of hand to camera
        :param com: center of mass, in image coordinates (x,y,z), z in mm
        :param size: (x,y,z) extent of the source crop volume in mm
        :param dsize: (x,y) extent of the destination size
        :return: cropped hand image, transformation matrix for joints, CoM in image coordinates
Crop area of hand in 3D volumina, scales inverse to the distance of hand to camera
        :param com: center of mass, in image coordinates (x,y,z), z in mm
        :param size: (x,y,z) extent of the source crop volume in mm
        :param dsize: (x,y) extent of the destination size
        :return: cropped hand image, transformation matrix for joints, CoM in image coordinates
Crop area of hand in 3D volumina scales inverse to the distance of hand to camera : param com : center of mass in image coordinates ( x y z ) z in mm : param size : ( x y z ) extent of the source crop volume in mm : param dsize : ( x y ) extent of the destination size : return : cropped hand image transformation matrix for joints CoM in image coordinates
def cropArea3D(self, com=None, size=(250, 250, 250), dsize=(128, 128), docom=False):
        """
        Crop area of hand in 3D volumina, scales inverse to the distance of hand to camera
        :param com: center of mass, in image coordinates (x,y,z), z in mm
        :param size: (x,y,z) extent of the source crop volume in mm
        :param dsize: (x,y) extent of the destination size
        :return: cropped hand image, transformation matrix for joints, CoM in image coordinates
        """

        #print com, self.importer.jointImgTo3D(com)
        #import matplotlib.pyplot as plt
        #import matplotlib
        #fig = plt.figure()
        #ax = fig.add_subplot(111)
        #ax.imshow(self.dpt, cmap=matplotlib.cm.jet)

        if len(size) != 3 or len(dsize) != 2:
            raise ValueError("Size must be 3D and dsize 2D bounding box")

        if com is None:
            com = self.calculateCoM(self.dpt)

        # calculate boundaries
        xstart, xend, ystart, yend, zstart, zend = self.comToBounds(com, size)
        #print xstart-xend,ystart-yend


        # crop patch from source
        cropped = self.getCrop(self.dpt, xstart, xend, ystart, yend, zstart, zend)
        #ax.plot(com[0],com[1],marker='.')
        #
        # plt.imshow(cropped)
        # plt.show()
        #############
        # for simulating COM within cube
        if docom is True:
            com = self.calculateCoM(cropped)
            if numpy.allclose(com, 0.):
                com[2] = cropped[cropped.shape[0]//2, cropped.shape[1]//2]
                if numpy.isclose(com[2], 0):
                    com[2] = 300
            com[0] += xstart
            com[1] += ystart

            # calculate boundaries
            xstart, xend, ystart, yend, zstart, zend = self.comToBounds(com, size)


            # crop patch from source
            cropped = self.getCrop(self.dpt, xstart, xend, ystart, yend, zstart, zend)
        # ax.plot(com[0],com[1],marker='x')

        ##############
        if docom is True and self.refineNet is not None and self.importer is not None:
            rz = self.resizeCrop(cropped, dsize)
            newCom3D = self.refineCoM(rz, size, com) + self.importer.jointImgTo3D(com)
            com = self.importer.joint3DToImg(newCom3D)
            if numpy.allclose(com, 0.):
                com[2] = cropped[cropped.shape[0]//2, cropped.shape[1]//2]

            # calculate boundaries
            xstart, xend, ystart, yend, zstart, zend = self.comToBounds(com, size)

            # crop patch from source
            cropped = self.getCrop(self.dpt, xstart, xend, ystart, yend, zstart, zend)

        # ax.plot(com[0],com[1],marker='o')
        #plt.show(block=True)

        #############
        wb = (xend - xstart)
        hb = (yend - ystart)
        if wb > hb:
            sz = (dsize[0], hb * dsize[0] / wb)
        else:
            sz = (wb * dsize[1] / hb, dsize[1])

        # print com, sz, cropped.shape, xstart, xend, ystart, yend, hb, wb, zstart, zend
        trans = numpy.eye(3)
        trans[0, 2] = -xstart
        trans[1, 2] = -ystart
        if cropped.shape[0] > cropped.shape[1]:
            scale = numpy.eye(3) * sz[1] / float(cropped.shape[0])
        else:
            scale = numpy.eye(3) * sz[0] / float(cropped.shape[1])
        scale[2, 2] = 1

        # depth resize
        rz = self.resizeCrop(cropped, sz)

        #pylab.imshow(rz); pylab.gray();t=transformPoint2D(com,scale*trans);pylab.scatter(t[0],t[1]); pylab.show()

        ret = numpy.ones(dsize, numpy.float32) * self.getNDValue()  # use background as filler

        xstart = int(numpy.floor(dsize[0] / 2. - rz.shape[1] / 2.))
        xend = int(xstart + rz.shape[1])
        ystart = int(numpy.floor(dsize[1] / 2. - rz.shape[0] / 2.))
        yend = int(ystart + rz.shape[0])
        ret[ystart:yend, xstart:xend] = rz
        # print rz.shape, xstart, ystart
        off = numpy.eye(3)
        off[0, 2] = xstart
        off[1, 2] = ystart

        # import matplotlib.pyplot as plt
        # fig = plt.figure()
        # ax = fig.add_subplot(131)
        # ax.imshow(cropped, cmap='jet')
        # ax = fig.add_subplot(132)
        # ax.imshow(rz, cmap='jet')
        # ax = fig.add_subplot(133)
        # ax.imshow(ret, cmap='jet')
        # plt.show(block=True)

        # print trans,scale,off,numpy.dot(off, numpy.dot(scale, trans))
        return ret, numpy.dot(off, numpy.dot(scale, trans)), com
def cropArea3D ( self , com = None , size = ( 250 , 250 , 250 ) , dsize = ( 128 , 128 ) , docom = False ) : #print com, self.importer.jointImgTo3D(com) #import matplotlib.pyplot as plt #import matplotlib #fig = plt.figure() #ax = fig.add_subplot(111) #ax.imshow(self.dpt, cmap=matplotlib.cm.jet) if len ( size ) != 3 or len ( dsize ) != 2 : raise ValueError ( "Size must be 3D and dsize 2D bounding box" ) if com is None : com = self . calculateCoM ( self . dpt ) # calculate boundaries xstart , xend , ystart , yend , zstart , zend = self . comToBounds ( com , size ) #print xstart-xend,ystart-yend # crop patch from source cropped = self . getCrop ( self . dpt , xstart , xend , ystart , yend , zstart , zend ) #ax.plot(com[0],com[1],marker='.') # # plt.imshow(cropped) # plt.show() ############# # for simulating COM within cube if docom is True : com = self . calculateCoM ( cropped ) if numpy . allclose ( com , 0. ) : com [ 2 ] = cropped [ cropped . shape [ 0 ] // 2 , cropped . shape [ 1 ] // 2 ] if numpy . isclose ( com [ 2 ] , 0 ) : com [ 2 ] = 300 com [ 0 ] += xstart com [ 1 ] += ystart # calculate boundaries xstart , xend , ystart , yend , zstart , zend = self . comToBounds ( com , size ) # crop patch from source cropped = self . getCrop ( self . dpt , xstart , xend , ystart , yend , zstart , zend ) # ax.plot(com[0],com[1],marker='x') ############## if docom is True and self . refineNet is not None and self . importer is not None : rz = self . resizeCrop ( cropped , dsize ) newCom3D = self . refineCoM ( rz , size , com ) + self . importer . jointImgTo3D ( com ) com = self . importer . joint3DToImg ( newCom3D ) if numpy . allclose ( com , 0. ) : com [ 2 ] = cropped [ cropped . shape [ 0 ] // 2 , cropped . shape [ 1 ] // 2 ] # calculate boundaries xstart , xend , ystart , yend , zstart , zend = self . comToBounds ( com , size ) # crop patch from source cropped = self . getCrop ( self . dpt , xstart , xend , ystart , yend , zstart , zend ) # ax.plot(com[0],com[1],marker='o') #plt.show(block=True) ############# wb = ( xend - xstart ) hb = ( yend - ystart ) if wb > hb : sz = ( dsize [ 0 ] , hb * dsize [ 0 ] / wb ) else : sz = ( wb * dsize [ 1 ] / hb , dsize [ 1 ] ) # print com, sz, cropped.shape, xstart, xend, ystart, yend, hb, wb, zstart, zend trans = numpy . eye ( 3 ) trans [ 0 , 2 ] = - xstart trans [ 1 , 2 ] = - ystart if cropped . shape [ 0 ] > cropped . shape [ 1 ] : scale = numpy . eye ( 3 ) * sz [ 1 ] / float ( cropped . shape [ 0 ] ) else : scale = numpy . eye ( 3 ) * sz [ 0 ] / float ( cropped . shape [ 1 ] ) scale [ 2 , 2 ] = 1 # depth resize rz = self . resizeCrop ( cropped , sz ) #pylab.imshow(rz); pylab.gray();t=transformPoint2D(com,scale*trans);pylab.scatter(t[0],t[1]); pylab.show() ret = numpy . ones ( dsize , numpy . float32 ) * self . getNDValue ( ) # use background as filler xstart = int ( numpy . floor ( dsize [ 0 ] / 2. - rz . shape [ 1 ] / 2. ) ) xend = int ( xstart + rz . shape [ 1 ] ) ystart = int ( numpy . floor ( dsize [ 1 ] / 2. - rz . shape [ 0 ] / 2. ) ) yend = int ( ystart + rz . shape [ 0 ] ) ret [ ystart : yend , xstart : xend ] = rz # print rz.shape, xstart, ystart off = numpy . eye ( 3 ) off [ 0 , 2 ] = xstart off [ 1 , 2 ] = ystart # import matplotlib.pyplot as plt # fig = plt.figure() # ax = fig.add_subplot(131) # ax.imshow(cropped, cmap='jet') # ax = fig.add_subplot(132) # ax.imshow(rz, cmap='jet') # ax = fig.add_subplot(133) # ax.imshow(ret, cmap='jet') # plt.show(block=True) # print trans,scale,off,numpy.dot(off, numpy.dot(scale, trans)) return ret , numpy . dot ( off , numpy . dot ( scale , trans ) ) , com