Exemple #1
0
def test_blockSize(imgL, imgR, resultPath = 'test_blockSize'):
    """
    Test different value of blockSize in range of [0,25]
    """

    matcher_paramaters = init_matcher_parameters()

    if not os.path.exists(resultPath):
        os.makedirs(resultPath)

    for blockSize in range(3, 29):
        file_name = 'result' + str(blockSize) + '.jpg'

        print("Saving file " + file_name)

        change_blockSize(matcher_paramaters, blockSize)

        dmc_2 = DepthMapCreator_2(matcher_paramaters)

        depth_image = dmc_2.get_depth_image(imgL, imgR)

        font = cv2.FONT_HERSHEY_SIMPLEX
        #cv2.putText(depth_image, str(executing_time),(10,10), font, 0.3,(255,255,255),1,cv2.LINE_AA)

        cv2.imwrite(os.path.join(resultPath, file_name), depth_image)
Exemple #2
0
def test_numDisparities(imgL, imgR, resultPath = 'test_numDisparities'):
    """
    Test different value of numDisparities with multiplier in range of [1, 25]
    """

    matcher_paramaters = init_matcher_parameters()

    if not os.path.exists(resultPath):
        os.makedirs(resultPath)

    for multiplier in range(1, 25):
        numDisparities = 16 * multiplier
        file_name = 'result' + str(numDisparities) + '.jpg'

        change_numDisparities(matcher_paramaters, numDisparities)

        dmc_2 = DepthMapCreator_2(matcher_paramaters)


        depth_image = dmc_2.get_depth_image(imgL, imgR)

        font = cv2.FONT_HERSHEY_SIMPLEX
        #cv2.putText(depth_image, str(executing_time),(10,10), font, 0.3,(255,255,255),1,cv2.LINE_AA)

        cv2.imwrite(os.path.join(resultPath, file_name), depth_image)
Exemple #3
0
def test_depth_map_format():
    '''
    Verify that function returns non-empty numpy.uint8 object
    '''

    left_file = np.ones((270, 480, 3), dtype=np.uint8)
    right_file = np.ones((270, 480, 3), dtype=np.uint8)*2
    depth_map_creator = DepthMapCreator_2()
    depth_map = depth_map_creator.get_depth_image(left_file, right_file)
    assert depth_map is not None
    assert depth_map.shape == (270, 480)
Exemple #4
0
def test_empty_arguments():
    '''
    Verify that function raises error if input does not exist
    '''
    left_file = np.ones((270, 480, 3), dtype=np.uint8)
    right_file = np.ones((270, 480, 3), dtype=np.uint8)*2

    depth_map_creator = DepthMapCreator_2()

    with pytest.raises(ValueError):
        depth_map_creator.get_depth_image(None, right_file)

    with pytest.raises(ValueError):
        depth_map_creator.get_depth_image(left_file, None)

    with pytest.raises(ValueError):
        depth_map_creator.get_depth_image(None, None)
Exemple #5
0
def test_windowSize(imgL, imgR, resultPath = 'windowSizeResult'):
    """
    Test different value of windowSize in range of [0,25]
    """

    matcher_paramaters = init_matcher_parameters()
    dmc_2 = DepthMapCreator_2(matcher_paramaters)


    if not os.path.exists(resultPath):
        os.makedirs(resultPath)

    for windowSize in range(50):
        file_name = 'result' + str(windowSize) + '.jpg'

        dmc_2.set_window_size(windowSize)
        depth_image = dmc_2.get_depth_image(imgL, imgR)
        font = cv2.FONT_HERSHEY_SIMPLEX
        #cv2.putText(depth_image, str(executing_time),(10,10), font, 0.3,(255,255,255),1,cv2.LINE_AA)

        cv2.imwrite(os.path.join(resultPath, file_name), depth_image)
Exemple #6
0
def test_DMC_2(imgL, imgR):
    matcher_parameters = init_matcher_parameters(windowSize=5,
                            minDisparity = 0,
                            numDisparities = 16 * 3,
                            blockSize = 5,
                            disp12MaxDiff = 1,
                            uniquenessRatio = 5,
                            speckleWindowSize = 0,
                            speckleRange = 2,
                            preFilterCap=63,
                            mode = cv2.STEREO_SGBM_MODE_SGBM)

    dmc_2 = DepthMapCreator_2(matcher_parameters)

    depth_image = dmc_2.get_depth_image(imgL, imgR)

    font = cv2.FONT_HERSHEY_SIMPLEX
    #cv2.putText(depth_image, str(executing_time),(10,10), font, 0.3,(255,255,255),1,cv2.LINE_AA)

    cv2.imwrite("test_DMC2.jpg", depth_image)

    return depth_image
Exemple #7
0
def test_speckleWindowSize(imgL, imgR, resultPath = 'test_speckleWindowSize'):
    """
    Test different value of speckleWindowSize with multiplier in range of [50, 200]
    """

    matcher_paramaters = init_matcher_parameters()

    if not os.path.exists(resultPath):
        os.makedirs(resultPath)

    for value in range(50, 200):
        file_name = 'result' + str(value) + '.jpg'

        change_speckleWindowSize(matcher_paramaters, value)

        dmc_2 = DepthMapCreator_2(matcher_paramaters)

        depth_image = dmc_2.get_depth_image(imgL, imgR)

        font = cv2.FONT_HERSHEY_SIMPLEX
        #cv2.putText(depth_image, str(executing_time),(10,10), font, 0.3,(255,255,255),1,cv2.LINE_AA)

        cv2.imwrite(os.path.join(resultPath, file_name), depth_image)
Exemple #8
0
def test_both_methods(imgL, imgR):
    """
    Make function calls of DepthMapCreator and DepthCreator_2
    Visually compare output
    """
    matcher_parameters = init_matcher_parameters(windowSize=3,
                            minDisparity = 16,
                            numDisparities = 16,
                            blockSize = 15,
                            disp12MaxDiff = 1,
                            uniquenessRatio = 10,
                            speckleWindowSize = 100,
                            speckleRange = 32,
                            mode = cv2.STEREO_SGBM_MODE_SGBM)

    # FILTER Parameters
    filter_parameters = dict()
    filter_parameters['lmbda'] = 80000
    filter_parameters['sigma'] = 1.2

    dmc = DepthMapCreator(filter_parameters, matcher_parameters)
    dmc_2 = DepthMapCreator_2(matcher_parameters)

    return dmc, dmc_2
Exemple #9
0
def test_allParameters(imgL, imgR,
                        minDisp_list = [0, 16],
                        numDisp_multiplier_list = [6, 7, 8],
                        blockSize_list = [3, 7, 11],
                        speckleRange_list = [32],
                        sWS_list = [100],
                        windowSize_list = [3, 5, 7],
                        disp12MaxDiff_list = [1],
                        preFilterCap_list = [100],
                        uniquenessRatio_list = [15],
                        resultPath = 'test_allParameters_1'):
    """
    Parameters to tests:
        minDisparity(md):
        numDisparity(nd):
        blockSize(bs):
        speckleRange(sR) :
        speckleWindowSize(sWS):
        disp12MaxDiff(d12MD)
        windowSize(wS):
        preFilterCap(pFC):
        uniquenessRatio(uR):
    """

    print('Test all parameters')
    matcher_paramaters = init_matcher_parameters()

    if not os.path.exists(resultPath):
        os.makedirs(resultPath)

    for md in minDisp_list:
        change_minDisparity(matcher_paramaters, md)

        for multiplier in numDisp_multiplier_list:
            nd = multiplier * 16
            change_numDisparities(matcher_paramaters, nd)

            for bS in blockSize_list:
                change_blockSize(matcher_paramaters, bS)

                for sR in speckleRange_list:
                    change_speckleRange(matcher_paramaters, sR)

                    for sWS in sWS_list:
                        change_speckleWindowSize(matcher_paramaters, sWS)

                        for d12MD in disp12MaxDiff_list:
                            change_disp12MaxDiff(matcher_paramaters, d12MD)

                            dmc_2 = DepthMapCreator_2(matcher_paramaters)

                            for wS in windowSize_list:
                                dmc_2.set_window_size(wS)

                                for pFC in preFilterCap_list:
                                    dmc_2.set_preFilterCap(pFC)

                                    for uR in uniquenessRatio_list:
                                        dmc_2.set_uniquenessRatio(uR)

                                        file_name = 'md'  + str(md) + '_nd' + str(nd) + '_bS' + str(bS) + '_sR' + str(sR) + '_sWS' + str(sWS) + '_d12MD' + str(d12MD) + '_wS' + str(wS) + '_pFC' + str(pFC) + '_uR' + str(uR) + '.jpg'
                                        print(file_name + ' is processing ...')

                                        depth_image = dmc_2.get_depth_image(imgL, imgR)

                                        font = cv2.FONT_HERSHEY_SIMPLEX
                                        #cv2.putText(depth_image, str(executing_time),(10,10), font, 0.3,(255,255,255),1,cv2.LINE_AA)

                                        cv2.imwrite(os.path.join(resultPath, file_name), depth_image)