示例#1
0
def computeData(scene):
    data_list = []

    isophote_mesh = scene.isophoteMesh()
    isophote_curves = isophote_mesh.isophoteCurves()

    for isophote_curve in isophote_curves:
        isophote_segments = isophote_curve.toCurveSegments()

        for isophote_segment in isophote_segments:
            I = isophote_segment.isoValue()
            I = 2.0 * I - 1.0

            normals_gt = isophote_segment.normals()
            parameters = isophote_segment.arcLengthParameters()
            normals_al = NormalConeInterpolation(normals_gt[0],
                                                 normals_gt[-1],
                                                 isophote_segment.lightDir(),
                                                 I).interpolate(parameters)
            ps = isophote_segment.points()

            normals_error = normVectors(normals_gt - normals_al)

            data_list.append({"ps": ps,
                              "normals_gt": normals_gt,
                              "normals_al": normals_al,
                              "normals_error": normals_error})
    return data_list
示例#2
0
def cleanNormal(N_32F, A_8U):
    # N_32F = cv2.bilateralFilter(N_32F, 0, 0.1, 5)
    h, w = N_32F.shape[:2]

    plt.subplot(1, 2, 1)
    plt.gray()
    plt.imshow(normVectors(N_32F.reshape(-1, 3)).reshape(h, w))

    plt.subplot(1, 2, 2)
    plt.gray()
    A_32F = to32F(A_8U)
    A_32F = cv2.GaussianBlur(A_32F, (0, 0), 3.0)
    A_32F = np.clip(10.0 * (A_32F - 0.5) + 0.5, 0.0, 1.0)
    A_32F = cv2.GaussianBlur(A_32F, (0, 0), 3.0)
    N_fix = A_32F > 0.9
    N_bg = A_32F < 0.25
    A_32F = np.clip(10.0 * (A_32F - 0.5) + 0.5, 0.0, 1.0)
    A_8U = to8U(A_32F)
#     plt.imshow(A_8U)
#     plt.show()

    N_32F_blur = cv2.GaussianBlur(N_32F, (0, 0), 3.0)
    for i in xrange(10):
        N_32F_blur = cv2.GaussianBlur(N_32F_blur, (0, 0), 3.0)
        N_32F_blur[N_fix, :] = N_32F[N_fix, :]

    N_32F = N_32F_blur
    # N_32F[N_bg, 2] = 0.0
    N_32F_normalized = normalizeImage(N_32F)

    #A_8U = np.uint8(np.clip(1000.0 * N_32F_normalized[:, :, 2], 0.0, 255.0))
    # A_8U = cv2.bilateralFilter(A_8U, 0, 70, 5)

    return N_32F_normalized, A_8U
def estimateLbyDistance(cvs_sil, N_sil, I_32F):
    I_sampling = PixelSampling(I_32F, num_pixels = 10000)
    I_samples = I_sampling.pixels()
    I_coords = I_sampling.coordinates()

    I_large_ids = I_samples > 0.5 * np.max(I_samples)
#     I_max_id = np.argmax(I_samples)
#     I_max_coord = I_coords[I_max_id]
#
#     print I_max_coord, I_samples[I_max_id], np.max(I_samples)
    L = np.array([0.0, 0.0, 0.0])
    hist = 0.0
    for I_large_id in I_large_ids:
        I_coord = I_coords[I_large_id]
        dist = normVectors(cvs_sil - I_coord)
        dist_max = np.max(dist)
        w = np.exp(- (dist ** 2) / (0.2 * dist_max**2))
        w *= 1.0 / np.sum(w)

        L_i = np.dot(w, N_sil)
        L += L_i
        hist += 1.0

    if hist > 0.0:
        L /= hist
    print L

    Lz = np.sqrt(1.0 - np.dot(L, L))
    L[2] = Lz
    print L.shape
    L = normalizeVector(L)
    return L
示例#4
0
def computeArcLengthParameters(points):
    diff_points = points[1:, :] - points[:-1, :]
    dist_points = normVectors(diff_points)

    dist_sum = np.sum(dist_points)

    parameters = np.zeros(len(points))

    arc_length = 0
    for pi in range(len(dist_points)):
        arc_length += dist_points[pi]
        parameters[pi + 1] = arc_length

    if dist_sum > 0.00001:
        parameters *= (1.0 / dist_sum)
    logger.debug("Total arc length: %s" % dist_sum)

    return parameters
示例#5
0
    def computeParameters(self):
        cvs = self._points

        diff_cvs = cvs[1:, :] - cvs[:-1, :]
        dist_cvs = normVectors(diff_cvs)

        al_total = np.sum(dist_cvs)

        params = np.zeros(len(cvs))

        al = 0
        for pi in range(len(cvs) - 1):
            al += dist_cvs[pi]
            params[pi + 1] = al

        if al_total > 0.00001:
            params *= (1.0 / al_total)

        self._params = params