예제 #1
0
                                          mode=cv.RETR_TREE,
                                          method=cv.CHAIN_APPROX_NONE)

    largest_contour_index = my_functions.get_contour_max_area(contours)[0]

    # only print if interested
    # print(largest_contour_index)

    if largest_contour_index == 0:
        continue

    largest_contoured_polygon = cv.approxPolyDP(
        contours[largest_contour_index],
        0.05 * cv.arcLength(contours[largest_contour_index], True), True)

    frame_BGR_cropped = my_functions.crop_image(frame_BGR_resized,
                                                largest_contoured_polygon)

    # Displaying images except the original before resizing
    my_functions.open_in_location(frame_BGR_resized, "Original Frame Scaled",
                                  0, 10)
    my_functions.open_in_location(frame_GRAY_blured, "Gray Filtered Frame",
                                  400, 10)
    my_functions.open_in_location(frame_THRESHOLDED, "Thresholded Frame", 800,
                                  10)
    my_functions.open_in_location(frame_BGR_cropped, "Original Frame Cropped",
                                  1200, 10)

    cv.waitKey()
    cv.destroyAllWindows()
예제 #2
0
    frame_canny = cv.Canny(frame_GRAY, lower_TH_level, upper_TH_level)

    lines = cv.HoughLinesP(frame_canny,
                           1,
                           np.pi / 90,
                           80,
                           minLineLength=100,
                           maxLineGap=25)
    if lines is None:
        print("error, image has no lines")
        continue

    for line in lines:
        x1, y1, x2, y2 = line[0]
        cv.line(frame_BGR_resized_2, (x1, y1), (x2, y2), (0, 255, 0), 2)

    Hough_points = my_functions.hough_square_absolute_maximum(lines)
    frame_BGR_Cropped = frame_BGR_resized[Hough_points[1]:Hough_points[3],
                                          Hough_points[0]:Hough_points[2]]

    # Displaying images except the original before resizing
    my_functions.open_in_location(frame_BGR_resized, "Original Frame Scaled",
                                  0, 10)
    my_functions.open_in_location(frame_canny, "Canny Edge", 400, 10)
    my_functions.open_in_location(frame_BGR_resized_2, "Hough Lines", 800, 10)
    my_functions.open_in_location(frame_BGR_Cropped, "Original Frame Cropped",
                                  1200, 10)

    cv.waitKey()
    cv.destroyAllWindows()
예제 #3
0
#My fucntions
import my_functions


directory=r'D:\learning\Semesters\Semester 8\Image_Processing\Project\Chess_board_sampels'
imges= my_functions.load_images_from_source(directory,2)


for i in range(len(imges)):

    print("Chess_image_"+str(i+1))

    org =my_functions.resize_image(imges[i],10)
    org_2 = org
    img=cv.cvtColor(org,cv.COLOR_BGR2GRAY)
    my_functions.open_in_location(img,"Chess_image_"+str(i+1),-1347,-165)

    canny= cv.Canny(img, 80, 150)
    #canny_2=canny
    blur = cv.GaussianBlur(img, (5, 5), 3)
    my_functions.open_in_location(blur,'Gaussian Blur '+str(i+1),-905,-165)


    thrsh = cv.adaptiveThreshold(blur, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY , 11,2)
    #_, img = cv.threshold(img, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
    contours, hierarchy = cv.findContours(thrsh, mode = cv.RETR_TREE, method = cv.CHAIN_APPROX_NONE)

    max = (my_functions.get_contour_max_area(contours))[0]
    if max==0:
        continue
import numpy as np
# My fucntions
import my_functions


number_of_images_in_source = 10
source = r'D:\learning\Semesters\Semester 8\Image_Processing\Project\Chess_board_sampels_3'
directory = r'D:\learning\Semesters\Semester 8\Image_Processing\Project\all_cropped'
frame_BGR_original = my_functions.load_images_from_source(source, number_of_images_in_source - 1)


for c in range(number_of_images_in_source):

    frame_BGR_resized = my_functions.resize_image(frame_BGR_original[c], 10)
    frame_BGR_resized_2=frame_BGR_resized
    my_functions.open_in_location(frame_BGR_resized, "Original Frame Scaled", 0, 10)

    frame_GRAY = cv.cvtColor(frame_BGR_resized, cv.COLOR_BGR2GRAY)
    frame_GRAY_blured=cv.GaussianBlur(frame_GRAY,(5,5),0)

    GRAY_corners = cv.goodFeaturesToTrack(frame_GRAY, 100, 0.4, 5)
    corners_array = np.int0(GRAY_corners)


    #Display the corners found int he image

    for i in corners_array:
        x, y = i.ravel()
        cv.circle(frame_BGR_resized_2, (x, y), 3, [255, 255, 0], -1)

예제 #5
0
import pause

#My fucntions
import my_functions

directory = r'D:\learning\Semesters\Semester 8\Image_Processing\Project\Chess_board_sampels_2'
imges = my_functions.load_images_from_source(directory, 50)

for i in range(len(imges)):

    print("Chess_image_" + str(i + 1))

    org = my_functions.resize_image(imges[i], 10)
    org_2 = org
    img = cv.cvtColor(org, cv.COLOR_BGR2GRAY)
    my_functions.open_in_location(img, "Chess_image_" + str(i + 1), -1347,
                                  -165)

    canny = cv.Canny(img, 80, 150)
    #canny_2=canny
    blur = cv.GaussianBlur(img, (5, 5), 3)
    thrsh = cv.adaptiveThreshold(blur, 255, 1, 1, 11, 2)
    '''
    lines = cv.HoughLinesP(thrsh, 1, np.pi / 90, 220, minLineLength=200, maxLineGap=8)
    if lines is None:
        print("error, image has no lines")
        continue

    for line in lines:
        x1, y1, x2, y2 = line[0]
        cv.line(org_2, (x1, y1), (x2, y2), (0, 255, 0), 2)