OpenCv с Python и я пытаюсь автоматически замаскировать прямоугольник для нескольких мест - PullRequest
0 голосов
/ 13 ноября 2018

Я работаю над этим изображением с помощью OpenCV, и я дошел до того, что потянул фотографию, оттенки серого, размыл и создал резкие линии. Сейчас я пытаюсь замаскировать каждое место и создать идентификатор для каждого. Так что я могу создать файл с булевой логикой, что-то там или нет. В моем чтении я обнаружил, где можно использовать мышь для рисования на изображении, но я ищу более автоматический подход. Может кто-нибудь помочь мне туда добраться. Parking Lot

import cv2
import numpy as np
import matplotlib
from matplotlib.pyplot import imshow
from matplotlib import pyplot as plt

#Get image to gray scale and process in GaussianBlur
img = cv2.imread('IMG_0940.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 

kernel_size = 5
blur_gray = cv2.GaussianBlur(gray,(kernel_size, kernel_size),0) #gray

#Process the edges of parking spots with Canny
low_threshold = 50
high_threshold = 150
edges = cv2.Canny(blur_gray, low_threshold, high_threshold)

#To get the lines of the parking spots use HoughLinesP
rho = 1  # distance resolution in pixels of the Hough grid
theta = np.pi / 180  # angular resolution in radians of the Hough grid
threshold = 15  # minimum number of votes (intersections in Hough grid cell)
min_line_length = 50  # minimum number of pixels making up a line
max_line_gap = 20  # maximum gap in pixels between connectable line segments
line_image = np.copy(img) * 0  # creating a blank to draw lines on

# Run Hough on edge detected image
# Output "lines" is an array containing endpoints of detected line segments
lines = cv2.HoughLinesP(edges, rho, theta, threshold, np.array([]),
            min_line_length, max_line_gap)

for line in lines:
for x1,y1,x2,y2 in line:
  cv2.line(line_image,(x1,y1),(x2,y2),(255,0,0),5)

#Draw the lines on the srcImage
lines_edges = cv2.addWeighted(img, 0.8, line_image, 1, 0)
cv2.imwrite('IMG_0940_LINES.png',lines_edges)
result = cv2.imread('IMG_0940_LINES.png')

cv2.namedWindow('Result',cv2.WINDOW_AUTOSIZE)
cv2.imshow('Result',result)
cv2.resizeWindow('Result',1000,1200)
cv2.waitKey(0)
cv2.destroyAllWindows()             #Closes all the windows
...