示例#1
0
def detect_slope_intercept(image):
    space = common.init_space(CONVERTED_SIZE, CONVERTED_SIZE)
    line = common.Line()

    point_list = get_points(image)

    for row in range(CONVERTED_SIZE):
        for point in point_list:
            # Change m range from [0, 2000] to [-10, 10]
            m = row / 100 - 10
            b = point[1] - m * point[0]  # y = mx + b  =>  b = y - mx

            # Change b range from [-1000, 1000] to [0, 2000]
            b_cast = int(b + 1000)

            # Change m range from [-10, 10] to [0, 2000]
            m_cast = int((m + 10) * 100)

            if 0 <= b_cast < CONVERTED_SIZE and 0 <= m_cast < CONVERTED_SIZE:
                space[b_cast][m_cast] += 1

    max_value = -1
    for b in range(CONVERTED_SIZE):
        for m in range(CONVERTED_SIZE):
            if space[b][m] > max_value:
                max_value = space[b][m]
                line.b = b - 1000
                line.m = m / 100 - 10

    return line
def detect_slope_intercept(image):
    line = common.Line()
    m_values = [x * 0.01 for x in range(-1000, 1000)]
    votes = common.init_space(2000, 2000)
    hough = common.init_space(2000, 2000)
    for i in range(2000):
        for j in range(2000):
            hough[i][j] = (0, 0)
    for y in range(common.constants.HEIGHT):
        for x in range(common.constants.WIDTH):
            pixel = (image[0][y][x], image[1][y][x], image[2][y][x])
            if pixel == (0, 0, 0):
                i = 0
                for m in m_values:
                    b = -x * m + y
                    if b >= -1000 and b < 1000:
                        votes[i][int(b) + 1000] = votes[i][int(b) + 1000] + 1
                        hough[i][int(b) + 1000] = (m, b)
                    i = i + 1
    max_votes = votes[0][0]
    for m in range(2000):
        for b in range(2000):
            if votes[m][b] >= max_votes:
                max_votes = votes[m][b]
                max_m = hough[m][b][0]
                max_b = hough[m][b][1]
    line.m = max_m
    line.b = max_b
    return line
示例#3
0
def detect_circles(image):
    space = common.init_space(HEIGHT, WIDTH)
    circle = common.Line()
    circle.r = 30
    circles_num = 0

    point_list = get_points(image)

    tot_steps = 2 * 360
    angle_per_step = 2 * math.pi / tot_steps

    for theta in range(tot_steps):
        for point in point_list:
            # (x - a)^2 + (y - b)^2 = r^2
            a = int(point[0] + circle.r * math.cos(angle_per_step * theta) + 1)
            b = int(point[1] - circle.r * math.sin(angle_per_step * theta) + 1)

            if 0 <= a < HEIGHT and 0 <= b < WIDTH:
                space[a][b] += 1

    for a in range(HEIGHT):
        for b in range(WIDTH):
            if space[a][b] > 650:
                circles_num += 1

    return circles_num
示例#4
0
def detect_slope_intercept(image):
    # PUT YOUR CODE HERE
    # access the image using "image[chanel][y][x]"
    # where 0 <= y < common.constants.WIDTH and 0 <= x < common.constants.HEIGHT
    # set line.m and line.b
    # to create an auxiliar bidimentional structure
    # you can use "space=common.init_space(heigh, width)"
    line = common.Line()
    hough_space = common.init_space(2000, 2000)
    for y in range(common.constants.HEIGHT):
        for x in range(common.constants.WIDTH):
            if ((image[0][y][x] == 0) and (image[1][y][x] == 0)
                    and (image[2][y][x] == 0)):
                for m_space in range(0, 2000):
                    m = float(m_space) / float(100) - 10
                    b = -(m * x) + y
                    if (b > -1000 and b < 1000):
                        hough_space[m_space][int(b) + 1000] += 1
    maximum = -1
    for y in range(2000):
        for x in range(2000):
            if hough_space[y][x] > maximum:
                maximum = hough_space[y][x]
                m = float(y) / 100 - 10
                b = x - 1000.4
    line.m = m
    line.b = b

    return line
def detect_normal(image):
    line = common.Line()
    pi = 3.14
    theta_values = [pi * (x / 1800.0) for x in range(0, 1800)]
    votes = common.init_space(2000, 2000)
    hough = common.init_space(2000, 2000)
    for i in range(1800):
        for j in range(1800):
            hough[i][j] = (0, 0)
    for y in range(common.constants.HEIGHT):
        for x in range(common.constants.WIDTH):
            pixel = (image[0][y][x], image[1][y][x], image[2][y][x])
            if pixel == (0, 0, 0):
                i = 0
                for theta in theta_values:
                    r = x * math.cos(theta) + y * math.sin(theta)
                    if r >= -900 and r < 900:
                        votes[i][int(r) + 900] = votes[i][int(r) + 900] + 1
                        hough[i][int(r) + 900] = (theta, r)
                    i = i + 1
    max_votes = votes[0][0]
    for theta in range(1800):
        for r in range(1800):
            if votes[theta][r] > max_votes:
                max_votes = votes[theta][r]
                max_theta = hough[theta][r][0]
                max_r = hough[theta][r][1]
    line.r = max_r
    line.theta = max_theta
    return line
示例#6
0
def detect_normal(image):
    # PUT YOUR CODE HERE
    # access the image using "image[chanel][y][x]"
    # where 0 <= y < common.constants.WIDTH and 0 <= x < common.constants.HEIGHT
    # set line.theta and line.r
    # to create an auxiliar bidimentional structure
    # you can use "space=common.init_spa
    line = common.Line()
    hough_space = common.init_space(1800, 1800)
    for y in range(common.constants.HEIGHT):
        for x in range(common.constants.WIDTH):
            if ((image[0][y][x] == 0) and (image[1][y][x] == 0)
                    and (image[2][y][x] == 0)):
                for theta_space in range(0, 1800):
                    theta = math.radians(float(theta_space) / float(10))
                    r = x * math.cos(theta) - y * math.sin(theta)
                    if (r > -900 and r < 900):
                        hough_space[theta_space][int(r) + 900] += 1
    maximum = -1
    for y in range(1800):
        for x in range(1800):
            if hough_space[y][x] > maximum:
                maximum = hough_space[y][x]
                theta = math.pi - math.radians(float(y) / float(10))
                r = 900 - x
    line.r = r
    line.theta = theta

    return line
示例#7
0
def detect_slope_intercept(image):
    # PUT YOUR CODE HERE
    # access the image using "image[y][x]"
    # where 0 <= y < common.constants.WIDTH and 0 <= x < common.constants.HEIGHT
    # set line.m and line.b
    # to create an auxiliar bidimentional structure
    # you can use "space=common.init_space(heigh, width)"

    line = common.Line()
    line.m = 0
    line.b = 0

    space = common.init_space(2000, 2000)

    for y in range(common.constants.HEIGHT):
        for x in range(common.constants.WIDTH):
            if image[y][x] == 0:
                for each in range(2000):
                    # scaling to get from xy to mb scale
                    m = (each / 100) - 10
                    b = -m * x + y
                    if 1000 > b > -1000:
                        space[each][int(b) + 100] += 1

    maxi = float("-inf")
    for y in range(2000):
        for x in range(2000):
            if space[y][x] > maxi:
                maxi = space[y][x]
                # scale m according to y, so divide by 100, 20 vs 2000, and then -10 for x axis adjustment.
                line.m = (y / 100) - 10
                line.b = x - 100

    return line
示例#8
0
def detect_slope_intercept(image):
    # PUT YOUR CODE HERE
    # access the image using "image[y][x]"
    # where 0 <= y < common.constants.WIDTH and 0 <= x < common.constants.HEIGHT
    # set line.m and line.b
    # to create an auxiliar bidimentional structure
    # you can use "space=common.init_space(heigh, width)"
    line = common.Line()
    line.m = 0
    line.b = 0
    (max_b, max_m) = (None, None)
    vote_space = [[0 for i in range(2000)] for j in range(2000)]
    for y in range(common.constants.WIDTH):
        for x in range(common.constants.HEIGHT):
            if image[y][x] == 0:
                m = -10  #init m value
                while (m <= 9.99):
                    b = y - m * x
                    if b >= -1000 and b <= 1000:
                        # print(f"b = {int(b)}, m = {m} at {round(100*(m + 10))}")
                        vote_space[round(b)][round(100 * (m + 10))] += 1

                    m += 0.01

    line.b, max_x = max_votespace(vote_space)
    # print(f"max vote: (b,m) = ({line.b, line.m})")
    line.m = round((max_x / 100) - 10, 3)

    return line
示例#9
0
def detect_slope_intercept(image):
	# PUT YOUR CODE HERE
	# access the image using "image[y][x]"
	# where 0 <= y < common.constants.WIDTH and 0 <= x < common.constants.HEIGHT 
	# set line.m and line.b
	# to create an auxiliar bidimentional structure 
	# you can use "space=common.init_space(heigh, width)"
	line=common.Line()
	line.m=0
	line.b=0
	return line
示例#10
0
def detect_normal(image, x_range, y_range):
    vote_box = [[0 for col in range(1800)] for row in range(1800)]
    for x in range(x_range):
        for y in range(y_range):
            if image[0][y][x] == 0 and image[1][y][x] == 0 and image[2][y][
                    x] == 0:
                vote_functions.vote_normal(x, y, vote_box)
    line = common.Line()
    data = auxiliary_functions.find_largest(vote_box, 1800)
    line.r = convert_values.index_to_value(data[1], 1800, -900, 900)
    line.theta = convert_values.index_to_value(data[0], 1800, 0, 3.14159)
    return line
示例#11
0
def detect_slope_intercept(image, x_range, y_range):
    vote_box = [[0 for col in range(2000)] for row in range(2000)]
    for x in range(x_range):
        for y in range(y_range):
            if image[0][y][x] == 0 and image[1][y][x] == 0 and image[2][y][
                    x] == 0:
                vote_functions.vote_slope(x, y, vote_box)
    data = auxiliary_functions.find_largest(vote_box, 2000)
    line = common.Line()
    line.m = convert_values.index_to_value(data[0], 2000, -10, 10)
    line.b = convert_values.index_to_value(data[1], 2001, -1000, 1000)
    return line
示例#12
0
def detect_normal(image):
    # PUT YOUR CODE HERE
    # access the image using "image[chanel][y][x]"
    # where 0 <= y < common.constants.WIDTH and 0 <= x < common.constants.HEIGHT
    # set line.theta and line.r
    # to create an auxiliar bidimentional structure
    # you can use "space=common.init_space(heigh, width)"
    line = common.Line()
    line.r = 0
    line.theta = 0

    max_x = 0
    max_y = 0

    H = [[[0.0 for x in range(3)] for x in range(1800)] for x in range(1800)]

    pi = 3.14159265
    incr = pi / 1800.0

    for i in range(len(image[0])):
        for j in range(len(image[0][0])):
            if ((image[2][i][j] == 0) and (image[0][i][j] == image[1][i][j])
                    and (image[1][i][j] == image[2][i][j])):
                theta = 0.0
                while theta < pi:
                    w = j * math.cos(theta) + i * math.sin(theta)
                    if (w >= -900.0 and w < 900.0):
                        y = int(theta * (1.0 / incr))
                        x = int(w + 900.0)

                        H[y][x][0] = H[y][x][0] + theta
                        H[y][x][1] = H[y][x][1] + w
                        H[y][x][2] = H[y][x][2] + 1.0
                        if (H[y][x][2] > H[max_y][max_x][2]):
                            max_y = y
                            max_x = x

                    theta += incr

    line.theta = H[max_y][max_x][0] / H[max_y][max_x][2]
    line.r = H[max_y][max_x][1] / H[max_y][max_x][2]

    return line
示例#13
0
def detect_slope_intercept(image):
    # PUT YOUR CODE HERE
    # access the image using "image[chanel][y][x]"
    # where 0 <= y < common.constants.WIDTH and 0 <= x < common.constants.HEIGHT
    # set line.m and line.b
    # to create an auxiliar bidimentional structure
    # you can use "space=common.init_space(heigh, width)"
    line = common.Line()
    line.m = 0
    line.b = 0

    hough_space = [[[0.0 for x in range(3)] for x in range(2000)]
                   for x in range(2000)]
    #print("done")

    max_x = 0
    max_y = 0
    incr = 20.0 / 2000.0

    for i in range(len(image[0])):
        for j in range(len(image[0][0])):
            if ((image[2][i][j] == 0) and (image[0][i][j] == image[1][i][j])
                    and (image[1][i][j] == image[2][i][j])):
                m = -10.0
                while (m < 10.0):
                    b = (m * -j) + i
                    if (b >= -1000.0 and b < 1000.0):
                        # select bin[y][x]
                        y = int((b + 1000))
                        x = int((m + 10) * 100)
                        hough_space[y][x][0] = hough_space[y][x][0] + b
                        hough_space[y][x][1] = hough_space[y][x][1] + m
                        hough_space[y][x][2] = hough_space[y][x][2] + 1
                        if (hough_space[y][x][2] >
                                hough_space[max_y][max_x][2]):
                            max_y = y
                            max_x = x
                    m += incr
    max_vote = hough_space[max_y][max_x]
    line.b = max_vote[0] / max_vote[2]
    line.m = max_vote[1] / max_vote[2]

    return line
示例#14
0
def detect_slope_intercept(image):
    # PUT YOUR CODE HERE
    # access the image using "image[chanel][y][x]"
    # where 0 <= y < common.constants.WIDTH and 0 <= x < common.constants.HEIGHT
    # set line.m and line.b
    # to create an auxiliar bidimentional structure
    # you can use "space=common.init_space(heigh, width)"
    line = common.Line()

    bmin = -1000
    bmax = 1000
    mmin = -10
    mmax = 10
    #line_space = {}
    space = common.init_space(2000, 2000)
    bestm = 0
    bestb = 0
    maxval = 0
    for y in range(common.constants.HEIGHT):
        for x in range(common.constants.WIDTH):
            r = image[0][y][x]
            g = image[1][y][x]
            b = image[2][y][x]
            if r == 0 and g == 0 and b == 0:  # black pixel
                # find feasible lines
                #b = y - m*x
                for m in range(2000):
                    mval = (m - 1000) * 0.01
                    b = y - mval * x
                    if b >= bmin and b <= bmax:
                        b = int(b)
                        space[m][b] += 1
                        if space[m][b] >= maxval:
                            bestb = b
                            bestm = mval
                            maxval = space[m][b]
    # find the highest voted line
    line.m = bestm
    line.b = bestb
    return line
示例#15
0
def detect_normal(image):
    # PUT YOUR CODE HERE
    # access the image using "image[chanel][y][x]"
    # where 0 <= y < common.constants.WIDTH and 0 <= x < common.constants.HEIGHT
    # set line.theta and line.r
    # to create an auxiliar bidimentional structure
    # you can use "space=common.init_space(heigh, width)"
    line = common.Line()

    space = common.init_space(1800, 1800)

    for y in range(common.constants.HEIGHT):
        for x in range(common.constants.WIDTH):
            r = image[0][y][x]
            g = image[1][y][x]
            b = image[2][y][x]
            if r == 0 and g == 0 and b == 0:  # black pixel
                for deg in range(1800):
                    R = x * math.cos(deg * math.pi / 1800) + y * math.sin(
                        deg * math.pi / 1800)
                    if R <= 900 and R >= -900:
                        R = int(R) + 900
                        space[R][deg] += 1
    bestR = 0
    bestdeg = 0
    maxval = 0
    for deg in range(1800):
        for R in range(1800):
            val = space[R][deg]
            if val >= maxval:
                maxval = val
                bestdeg = deg
                bestR = R
    line.r = bestR - 900
    line.theta = (bestdeg * math.pi / 1800)
    return line