def run_depth_utils_example():
    """
        FUNC: examples of basic usage of depth utils
    """
    #     # load binary depth file
    #     depthFile = './depth_data/a01_s01_e01_sdepth.bin'
    #     depthSequence = loadDepthFile(depthFile, fType = 'bin')

    # load png depth files in a given path
    depthFilePath = './depth_data/d_a01_s01_e01_sdepth/'
    depthSequence = loadDepthFile(depthFilePath, fType='png')

    for depthData in depthSequence:

        # show depth data
        showDepthData(depthData)

        # show 3d points
        points = getWorldCoordinates(depthData)
        visualizePointCloud(points)

        projData = getFrontDepthProjections(points, projSize=depthData.shape)
        #         projImg = getDepthProjections(points)
        showDepthData(projData)

        r_alpha = math.pi / 2.  # angle around x-axis
        r_beta = 0  # angle around y-axis

        r_points = rotatePoints(points, r_alpha, r_beta)
        visualizePointCloud(r_points)

        projData = getDepthProjection(r_points)
        showDepthData(projData)
def run_depth_utils_example():
    """
        FUNC: examples of basic usage of depth utils
    """
#     # load binary depth file
#     depthFile = './depth_data/a01_s01_e01_sdepth.bin'
#     depthSequence = loadDepthFile(depthFile, fType = 'bin')

    # load png depth files in a given path
    depthFilePath = './depth_data/d_a01_s01_e01_sdepth/'
    depthSequence = loadDepthFile(depthFilePath, fType = 'png')
    
    for depthData in depthSequence:
        
        # show depth data
        showDepthData(depthData)
        
        # show 3d points
        points = getWorldCoordinates(depthData)
        visualizePointCloud(points)
        
        projData = getFrontDepthProjections(points, projSize = depthData.shape)
#         projImg = getDepthProjections(points)
        showDepthData(projData)
        
        r_alpha = math.pi / 2.     # angle around x-axis
        r_beta = 0   # angle around y-axis
        
        r_points = rotatePoints(points, r_alpha, r_beta)
        visualizePointCloud(r_points)
        
        projData = getDepthProjection(r_points)
        showDepthData(projData)
def rotateDepthSequence(frames, r_alpha, r_beta):
    """
        FUNC: rotate depth frames in a sequence
        PARAM:
            frames: a list of frames
            r_alpha: angle around y-axis
            r_beta: angle around x-axis
        RETURN:
            r_frames: a list of rotated frames
    """
    r_frames = []
    for depthData in frames:
        points = getWorldCoordinates(depthData)
        r_points = rotatePoints(points, r_alpha, r_beta)
        projData = getDepthProjection(r_points, isCrop=False)
        r_frames.append(projData)
    
    return r_frames
Exemple #4
0
def rotateDepthSequence(frames, r_alpha, r_beta):
    """
        FUNC: rotate depth frames in a sequence
        PARAM:
            frames: a list of frames
            r_alpha: angle around y-axis
            r_beta: angle around x-axis
        RETURN:
            r_frames: a list of rotated frames
    """
    r_frames = []
    for depthData in frames:
        points = getWorldCoordinates(depthData)
        r_points = rotatePoints(points, r_alpha, r_beta)
        projData = getDepthProjection(r_points, isCrop=False)
        r_frames.append(projData)
    
    return r_frames


# def calWinDepthMHIList(frames, winSize, winStep):
#     """ calculate dmhi list using sliding window """
#     dmhiList = []
#     for i in xrange(0, len(frames), winStep):
#         startIdx = i
#         endIdx = i + winSize - 1
#         if endIdx <= len(frames) - 1:
# #             print "startIdx: %d, endIdx: %d" % (startIdx, endIdx)
#             winFrames = frames[startIdx:endIdx]
#             dmhiImg = calDepthMHI(winFrames)
#             dmhiList.append(dmhiImg)
#             
#     return dmhiList
# 
# 
# def calPyramidDepthMHIList(frames, dHOGTemporalPyramids):
#     """ calculate temporal Pyramid Depth MHI (PDMHI)  list"""
#     pdmhiList = []
#     for l in dHOGTemporalPyramids:
#         wantedParts = l
#         segmentedList = split_list(frames, wantedParts)
#         
#         for segment in segmentedList:
#             tmpFrames = segment
#             dmhiImg = calDepthMHI(tmpFrames)
#             
#             pdmhiList.append(dmhiImg)
#         
#     return  pdmhiList   
#     
# 
# def cropAndResizeImageList1(imageList, newSize = (128, 128)):
#     """ crop the image list and resize them (overall)"""
#     firstImg = imageList[0]
#     finalTop, finalBottom, finalLeft, finalRight = findBoxRegion(firstImg)
#     
#     for i in xrange(1, len(imageList)):
#         currImg = imageList[i]
#         currTop, currBottom, currLeft, currRight = findBoxRegion(currImg)
#         
#         if currTop < finalTop:
#             finalTop = currTop
#         
#         if currBottom > finalBottom:
#             finalBottom = currBottom
#         
#         if currLeft < finalLeft:
#             finalLeft = currLeft
#             
#         if currRight > finalRight:
#             finalRight = currRight
#             
#     postprocessImageList = []
#     for image in imageList:
#         cropedImage = image[finalTop:finalBottom, finalLeft:finalRight]
#         resizedImage = cv2.resize(cropedImage, newSize)
#         postprocessImageList.append(resizedImage)
#         
# #         # show image
# #         cv2.imshow('', resizedImage)
# #         cv2.waitKey()
#     
#     return postprocessImageList
#         
#     
# def findBoxRegion(image):
#     """ find the box region of given image """
#     # top
#     rows, cols = image.shape
#     top = 0
#     for r in xrange(rows):
#         row = image[r, :]
#         if sum(row) > 0:
#             top = r
#             break
#         
#     # bottom
#     bottom = rows - 1
#     for r in xrange(rows-1, -1, -1):
#         row = image[r, :]
#         if sum(row) > 0:
#             bottom = r
#             break;
#         
#     # left
#     left = 0
#     for c in xrange(cols):
#         col = image[:, c]
#         if sum(col) > 0:
#             left = c
#             break
#     
#     # right
#     right = cols - 1
#     for c in xrange(cols-1, -1, -1):
#         col = image[:, c]
#         if sum(col) > 0:
#             right = c
#             break
#         
#     return top, bottom, left, right
# 
# 
# def cropAndResizeImageList2(imageList, newSize = (128, 128)):
#     """ crop ROI from an image (one by one) """
#     postprocessImageList = []
#     for image in imageList:
#         top, bottom, left, right = findBoxRegion(image)
#         cropedImage = image[top:bottom, left:right]
#         resizedImage = cv2.resize(cropedImage, newSize)
#         postprocessImageList.append(resizedImage)
#         
#     return postprocessImageList
# 
# 
# def cropAndResizeImageList3(imageList, maxImSize = 300):
#     """ crop ROI from an image (one by one) """
#     postprocessImageList = []
#     for image in imageList:
#         top, bottom, left, right = findBoxRegion(image)
#         cropedImage = image[top:bottom, left:right]
#         resizedImage = resizeImage(cropedImage, maxImSize)
#         postprocessImageList.append(resizedImage)
#         
#     return postprocessImageList
# 
# 
# def resizeImage(originalImg, maxImSize):
#     """ 
#         maxImSize    -maximum size of the input image
#     """
#     nCols, nRows = originalImg.shape
#     
#     if max(nCols, nRows) > maxImSize:
#         fx = float(maxImSize)/max(nCols, nRows)
#         resizedImg = cv2.resize(originalImg, (0,0), fx=fx, fy=fx, interpolation = cv2.INTER_CUBIC) 
#     else:
#         resizedImg = originalImg.copy()
#         
#     return resizedImg
# 
# 
# def computeHMHT(imageList):
#     """ compute hierarchical motion history templates """
#     strides = config.strides
#     hmhtList = []
#     for stride in strides:
#         dmhiImg = calDepthMHI(imageList, motion_thresh = 10, stride = stride)
#         
#         # find ROI
#         top, bottom, left, right = findBoxRegion(dmhiImg)
#         cropedImage = dmhiImg[top:bottom, left:right]
#         resizedImage = cv2.resize(cropedImage, (128, 128))
#         hmhtList.append(resizedImage)
#         
#     return hmhtList