demo-int-table/test.py

56 lines
1.5 KiB
Python

import cv2
import numpy as np
# def image_resize(image, width = None, height = None, inter = cv2.INTER_AREA):
# # initialize the dimensions of the image to be resized and
# # grab the image size
# dim = None
# (h, w) = image.shape[:2]
# # if both the width and height are None, then return the
# # original image
# if width is None and height is None:
# return image
# # check to see if the width is None
# if width is None:
# # calculate the ratio of the height and construct the
# # dimensions
# r = height / float(h)
# dim = (int(w * r), height)
# # otherwise, the height is None
# else:
# # calculate the ratio of the width and construct the
# # dimensions
# r = width / float(w)
# dim = (width, int(h * r))
# # resize the image
# resized = cv2.resize(image, dim, interpolation = inter)
# # return the resized image
# return resized
img = cv2.imread(
"/home/arizona/projects/svs_tech/demo-int-table/admin_front/assets/img/plan.png"
)
(h, w) = img.shape[:2]
t = 1600
img = cv2.resize(img, (t, int((h/w) * t)))
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = 255 - gray
gray = cv2.blur(gray, (8, 1))
gray = cv2.threshold(gray, 1, 255, cv2.THRESH_BINARY)[1]
contours, hierarchy = cv2.findContours(gray, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
for cnt in contours:
area = cv2.contourArea(cnt)
if area > 150000 and area < 500000:
cv2.drawContours(img, [cnt], 0, (255, 0, 0), 2)
cv2.imshow("img", img)
cv2.waitKey()