Esempio n. 1
0
def make_contours(pict):

    #Openning picture
    img = open_picture(pict)

    #Filters.
    edges = filters(img)

    #Contours are writte into a black picture.
    contours, _ = cv2.findContours(edges, R, P)

    #Initialise dico
    name = "{}contour{}.png"
    dico_data = create_dico(len(contours), PIT, name)

    #Course contours
    for nb, cnt in enumerate(contours):

        #Create black empty picture
        blanck = blanck_picture(img)

        #Drawing contours
        cv2.drawContours(blanck, [cnt], -1, (255, 255, 255), 1)

        #Recup data
        dico_data = add_dico(dico_data, cnt, nb, name, PIT)

        #Save picture
        #cv2.imwrite(name.format(PIT, str(nb)), blanck)
        #show_picture("img", img, 0, "")

    #print(dico_data)
    return dico_data
Esempio n. 2
0
def points_placements(original, liste_information):

    original = img = open_picture(original)
    show_picture("original", original, 0, "")
    blanck = blanck_picture(img)

    liste = []
    minimum_distance = []
    for i in liste_information:

        img = open_picture(i[0])
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        #Recup white pixels from gray.
        liste_pointsX, liste_pointsY, all_points = recup_points(gray)
        recuperate_extremities_points(all_points, liste_pointsX, liste_pointsY,
                                      blanck, liste)

        #Recuperate last 2 forms connected from list.
        try:
            #print(liste[-2], "\n")
            #print(liste[-1])
            x1, y1, x2, y2 = recuperate_mini_distance(liste)
            minimum_distance.append((x1, y1, x2, y2))
            drawsing_lines(blanck, x1, y1, x2, y2, (255, 255, 255))
        except:
            pass

        #copy_blanck = cv2.resize(blanck, (800, 800))
        #show_picture("copy_blanck", copy_blanck, 0, "")

    #print(liste, "\n")
    #print(minimum_distance)

    return liste, minimum_distance
def finish_picture(img, blanck):
    R = cv2.RETR_TREE
    P = cv2.CHAIN_APPROX_NONE

    blanck1 = blanck_picture(img)
    cv2.imwrite("final.png", blanck)
    gray = cv2.cvtColor(blanck, cv2.COLOR_BGR2GRAY)


    contours, _ = cv2.findContours(gray, R, P)
    for cnt in contours:
        cv2.drawContours(blanck1, [cnt], -1, (255,255,255), 2)
        cv2.fillPoly(blanck1, pts =[cnt], color=(255, 255, 255))
    return blanck1
def drawing_main(original, oki_picture, a):

    img = open_picture(original)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    liste = min_distance(a)

    blanck = blanck_picture(img)
    for pict in range(len(oki_picture)):

        form1 = open_picture(oki_picture[pict][0])
        form1 = cv2.cvtColor(form1, cv2.COLOR_BGR2GRAY)

        form2 = open_picture(oki_picture[pict][1])
        form2 = cv2.cvtColor(form2, cv2.COLOR_BGR2GRAY)

        for i in range(len(oki_picture[pict])):

            if i == 0:
                form1 = form1
                form2 = form2
            else:
                form1 = form2
                form2 = form1

            #Draw form in function of passation
            draw_form(form1, blanck)

            #Recup pixel > 100
            liste_w = recup_points(form1)


            if i == 0:
                zone = draw_shema(liste[pict][1][0], liste[pict][0],
                                    liste[pict][1][1], liste[pict][1][2], blanck)

                draw_lines_to_zone(liste_w, liste, pict, blanck, zone)
            
                #print(zone)

                copy1 = cv2.resize(blanck, (800, 800))
                show_picture("copy1", copy1, 1, "")



    blanck1 = finish_picture(img, blanck)
    copy1 = cv2.resize(blanck1, (800, 800))
    show_picture("copy1", copy1, 0, "")
def sorting_list(points_detection, original, pictures):

    original = open_picture(original)
    show_picture("original", original, 0, "")
    blanck = blanck_picture(original)

    #Recuperate left position.
    liste_placement = left_position(points_detection)
    #print(liste_placement)

    #Recuperate name, position and coordinates.
    dico = name_position_points(pictures, points_detection, liste_placement)
    #print(dico)

    #Final information, name, position.
    position = final_informations(points_detection, dico)
    #print(liste_position)

    return blanck, position
Esempio n. 6
0
def main_connected(original, picture, minini):
    schema = ['corner4', 'lign verticale', 'corner7', 'lign horrizontale', 'corner5', 'corner6']

    img = open_picture(original)
    copy = img.copy()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    blanck = blanck_picture(img)

    #Sort list last, next picture 
    oki_picture = add_list_next_last(picture)
    #print(oki_picture)


    #Treat minini doublon list of list to list of list.
    treat_minini = treat_mini(minini)
    #print(minini)
    #print(treat_minini)

    #Schema with passation.
    dico_picture = schema_dico(len(treat_minini))
    #print(dico_picture)


    for nb in range(len(treat_minini)):
        blanck = blanck_picture(img)

        img1 = open_picture(oki_picture[nb][0])
        img2 = open_picture(oki_picture[nb][1])

        gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
        gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

        #Recuperate dimensions of picture
        height, width, chann = img1.shape

        #position of current form
        x = treat_minini[nb][0]
        y = treat_minini[nb][1]

        #Next form in red
        drawing(blanck, gray2, (0, 0, 255))



        find = False
        for i in schema:

            x = treat_minini[nb][0]
            y = treat_minini[nb][1]

            if i == "corner4":
                corner4(width, height, blanck, gray,
                         oki_picture, x, y, dico_picture, nb)

            elif i == 'lign verticale':
                lign_vertical(width, height, blanck, gray,
                              oki_picture, x, y, dico_picture, nb)

            elif i == 'corner7':
                corner7(width, height, blanck, gray,
                        oki_picture, x, y, dico_picture, nb)

            elif i == 'lign horrizontale':
                lign_horizontal(width, height, blanck, gray,
                                oki_picture, x, y, dico_picture, nb)

            elif i == 'corner5':
                corner5(width, height, blanck, gray,
                        oki_picture, x, y, dico_picture, nb)

            elif i == 'corner6':
                corner6(width, height, blanck, gray,
                        oki_picture, x, y, dico_picture, nb)


    print(dico_picture)
    print("")
    print(treat_minini)
    print("")
    print(oki_picture)


    return dico_picture, treat_minini, oki_picture