代码拉取完成,页面将自动刷新
#!/usr/local/bin/python
#-*-coding:utf-8-*-
import numpy as np
import cv2
from matplotlib import pyplot as plt
currentWindowId = 0
def prepareWindow(img, title, ifGray = False):
global currentWindowId
currentWindowId = currentWindowId +1
plt.subplot(3,3,currentWindowId)
plt.title(title)
plt.xticks([])
plt.yticks([])
if(ifGray):
plt.imshow(img,'gray')
else:
plt.imshow(img)
img = cv2.imread('room2.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
bg = thresh
prepareWindow(bg,"original", True)
kernel = np.ones((3,3),np.uint8)
#去噪音
bigObstacle = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE,kernel, iterations=2)
prepareWindow(bigObstacle,"real map", True)
cv2.imwrite('multiRoom.pgm',bigObstacle)
greyBigObstacle = bigObstacle
greyBigObstacle[bigObstacle<256] = 220
prepareWindow(greyBigObstacle,"graph",True)
cv2.imwrite('room_grey.pgm',greyBigObstacle)
plt.show()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。