建筑平面图中的门检测

时间:2020-04-19 07:35:51

标签: python opencv

我正在研究平面图图像中的房间检测项目,目前,我能够从图像中提取墙壁,但卡在门检测中。 我尝试使用电弧检测,但效果不佳。有人可以建议一种更好的方法。

def door_detection(r_img):
   gray =cv2.cvtColor(r_img,cv2.COLOR_BGR2GRAY)
   kernel = np.ones((5,5),np.uint8)
   erosion = cv2.erode(r_img, kernel, iterations=3)
   dilated = cv2.dilate(erosion,kernel,iterations = 3)
   blurred = cv2.medianBlur(dilated,5)
   canny = cv2.Canny(blurred,100,200)
   contours,hierarchy=cv2.findContours(canny,cv2.RETR_TREE, 
   cv2.CHAIN_APPROX_SIMPLE)
   contour_list=[]
   for contour in contours:
      approx = cv2.approxPolyDP(contour,0.01*cv2.arcLength(contour,True),True)
      area = cv2.contourArea(contour)
      if ((len(approx) > 10 & (area > 100) ):
          contour_list.append(contour)

   cv2.drawContours(r_img, contour_list,  -1, (255,0,0), 2)
   cv2.imshow('dilated',dilated)
   cv2.imshow('Objects Detected',r_img)
   cv2.imwrite('arcs.jpg',r_img)
   if cv2.waitKey(0) & 0xff == 27:
      cv2.destroyAllWindows()

0 个答案:

没有答案