Ask Your Question

Revision history [back]

I am trying to detect largest tile on the floor.

I am trying to detect the largest tile on the floor as shown in the link given below and highlight it with a green rectangle. Additionally, if the file is obstructed with an object, then this should not be highlighted.

Image - https://www.accessfloorsystems.com/media/catalog/product/cache/1/image/600x500/17f82f742ffe127f42dca9de82fb58b1/r/a/raised_computer_floor_tiles_cost_1.jpg

Code: - https://pastebin.com/MXQ8ai1e

# import the necessary packages
import imutils
from skimage import exposure
#import exposure
import numpy as np
import argparse
import cv2


# load the query image, compute the ratio of the old height
# to the new height, clone it, and resize it
image = cv2.imread('gb.jpg')
ratio = image.shape[0] / 300.0
orig = image.copy()
image = imutils.resize(image, height = 300)

# convert the image to grayscale, blur it, and find edges
# in the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray, 11, 17, 17)
edged = cv2.Canny(gray, 30, 200)

# find contours in the edged image, keep only the largest
# ones, and initialize our screen contour
cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:10]
screenCnt = None

# loop over our contours
for c in cnts:
    # approximate the contour
    peri = cv2.arcLength(c, True)
    approx = cv2.approxPolyDP(c, 0.02 * peri, True)

    # if our approximated contour has four points, then
    # we can assume that we have found our screen
    if len(approx) == 4:
        screenCnt = approx
        break


cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 3)
cv2.imshow("Game Boy Screen", image)
cv2.waitKey(0)