Esempio n. 1
0
def find_shapes(image):
    img = image
    blobs = extract_blobs(img)
    blobs2 = []
    h, w = img.shape
    y = h / 10
    x = w / 10

    for blob in blobs:
        #print('before removing '+ str(len(blob)))

        min_value = blob[0]
        max_value = blob[-1]
        if max_value[1] - min_value[1] < x * 5 and max_value[0] - min_value[
                0] < y * 5:  #and (len(blob) > 80):
            blobs2.append(blob)
    #for blob2 in blobs2:
    #print('after removing '+str(len(blob2)))
    blobs3 = coordinates(blobs2)
    for blob3 in blobs3:
        min_value = blob3[0]
        max_value = blob3[-1]
        #print('Min Value: '+str(min_value))
        #print('Max Value: ' + str(max_value))
        yield (min_value, max_value)
Esempio n. 2
0
def conversion(image):
    image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    cv2.imshow("image", image)
    lower_red = np.array([160, 80, 80])
    upper_red = np.array([190, 255, 255])
    #lower_green = np.array([20, 100, 40]); upper_green = np.array([80, 255, 255])

    mask_red = cv2.inRange(image, lower_red, upper_red)
    cv2.imshow("mask", mask_red)
    #mask_green = cv2.inRange(image, lower_green, upper_green)

    blob_red = extract_blobs(mask_red)
    #blob_green = extract_blobs(mask_green)

    correct_red = []
    #correct_green = []

    print("red")
    for red in blob_red:
        print(len(red))
        if len(red) > 4000:
            correct_red.append(red)
    """
    print("green")
    for green in blob_green:
        print(len(green))
        if len(green) > 1000:
            correct_green.append(green)
    """
    red_positions = coordinates(correct_red)
    #green_positions = coordinates(correct_green)
    print(red_positions)
    return red_positions
Esempio n. 3
0
def findBlobs(image):
    img = image
    blobs = extract_blobs(img)
    blobs2 = []
    for blob in blobs:
        if len(blob) > 4000:
            blobs2.append(blob)
Esempio n. 4
0
def calibration(image_to_crop):
    # Blur image
    blurred_image = cv2.cvtColor(image_to_crop, cv2.COLOR_BGR2GRAY)
    blurred_image = cv2.GaussianBlur(blurred_image, (21, 21),
                                     cv2.BORDER_DEFAULT)

    # Threshold and mask white
    #lower_white = np.array([90, 90, 90]); upper_white = np.array([255, 255, 255])

    binary_image = cv2.inRange(blurred_image, 130, 255)
    #cv2.imshow("gray", blurred_image)
    #cv2.imshow("mask", binary_image)
    cv2.imwrite("Evaluation/Grid_1/blobs.jpg", binary_image)

    # Find blob

    image_blobs = extract_blobs(binary_image)
    correct_blobs = []

    for blob in image_blobs:
        if len(blob) > 13000:

            correct_blobs.append(blob)

    coord = coordinates(correct_blobs)

    # Find placement grids
    player1_placement = (coord[0][0], coord[0][-1])
    #ratiox = coord[0][-1][0] - coord[0][0][0]
    #ratioy =  coord[0][-1][1] - coord[0][0][1]

    player2_placement = (coord[-1][0], coord[-1][-1])
    #player2_placement = (coord[-1][0], (coord[-1][0][0] + ratiox, coord[-1][0][1]  + ratioy))
    # Find attack grids
    player1_attack = (coord[1][0], coord[1][-1])
    #player1_attack = (coord[1][0], (coord[1][0][0] + ratiox, coord[1][0][1]  + ratioy))

    player2_attack = (coord[2][0], coord[2][-1])
    #player2_attack = (coord[2][0], (coord[2][0][0] + ratiox, coord[2][0][1]  + ratioy))

    # Return the coordinates to the function, hence turning the function into these values
    # These values can be accessed by refering to them as an array

    return ((player1_placement, player2_placement), (player1_attack,
                                                     player2_attack))
Esempio n. 5
0
def conversion(image):
    image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    lower_red = np.array([140, 80, 80])
    upper_red = np.array([190, 255, 255])

    mask_red = cv2.inRange(image, lower_red, upper_red)
    #cv2.imshow(".", mask_red)
    blob_red = extract_blobs(mask_red)
    correct_red = []

    print("red")
    for red in blob_red:
        print(len(red))
        if len(red) > 4000:
            correct_red.append(red)

    red_positions = coordinates(correct_red)
    #green_positions = coordinates(correct_green)
    print(red_positions)
    return red_positions
Esempio n. 6
0
                        binary_image[y_temp - 1, x_temp] = 0
                        queue.append([y_temp - 1, x_temp])

                    blob_pixels.append(queue.pop(0))
                blobs.append(blob_pixels)
    return blobs


back = cv2.imread('Pictures/empty.png')
curent = cv2.imread('Pictures/barrage.png')
cv2.imshow('smth', back)
cv2.imshow('smth2', curent)
w, h, c = back.shape
current_grey = cv2.cvtColor(curent, cv2.COLOR_BGR2GRAY)
current_greyB = cv2.GaussianBlur(current_grey, (7, 7), 0)
back_grey = cv2.cvtColor(back, cv2.COLOR_BGR2GRAY)
back_greyB = cv2.GaussianBlur(back_grey, (7, 7), 0)
difference = cv2.absdiff(back_greyB, current_greyB)
cv2.imshow('smth2', difference)
kernel = np.ones((5, 5), np.uint8)
img_binary = cv2.threshold(difference, 16, 255, cv2.THRESH_BINARY)[1]
erosion = cv2.erode(img_binary, kernel, iterations=2)
cv2.imshow('smth', erosion)
for r in extract_blobs(erosion):
    min_value = r[0]
    max_value = r[-1]
    print(min_value, max_value)
    for MinMax in shape_positions(r, w, h):
        print(MinMax)

cv2.waitKey(0)
Esempio n. 7
0
def findBlobs(image):
    blobs = extract_blobs(image)

    for blob in blobs:
        print(blob[0], blob[-1])