毕业设计的方向是变化检测,但是在两张图片都分类进行对比以后,总会有一些小的误差点,由于是编写了一整套程序,需要把结果呈现在网页上,所以为了美观,腐蚀掉一些小的分类误差点。代码是将小误差块的面积小于总面积的0.1,作为测试。
import numpy as np
import cv2
class Point(object):
def __init__(self, x, y):
self.x = x
self.y = y
def getX(self):
return self.x
def getY(self):
return self.y
def getGrayDiff(img, currentPoint, tmpPoint):
return abs(int(img[currentPoint.x, currentPoint.y]) - int(img[tmpPoint.x, tmpPoint.y]))
def selectConnects(p):
if p != 0:
connects = [Point(-1, -1), Point(0, -1), Point(1, -1), Point(1, 0), Point(1, 1), \
Point(0, 1), Point(-1, 1), Point(-1, 0)]
else:
connects = [Point(0, -1), Point(1, 0), Point(0, 1), Point(-1, 0)]
return connects
def regionGrow(img, seeds, thresh, p=1):
area = 0
height = img.shape[0]
weight = img.shape[