請檢查該代碼算法how to find area of rectangle which is covering another rectangle通過@Arun [R告訴什麼是錯在它爲什麼我的代碼不刪除內部矩形
我的輸出
爲什麼不刪除裏面的矩形其他
cdef class Ray:
cdef public:
Point2D p
Point2D q
list points
cdef class Boundbox:
cdef public:
Point2D minP
Point2D maxP
int componentID
int getComponentID(self):
return self.componentID
def __numeric_compare_by_x(self,Boundbox a,Boundbox b):
cdef Point2D tempA,tempB
tempA=a.minP
tempB=b.minP
return tempA.x-tempB.x
def __numeric_compare_by_y(self,Boundbox a,Boundbox b):
cdef Point2D tempA,tempB
tempA=a.minP
tempB=b.minP
return tempA.y-tempB.y
def isBoundbox_inside(self,b1,b2):
if((b1.minP.x<=b2.minP.x and b1.minP.y<=b2.minP.y)and(b1.maxP.x>=b2.maxP.x and b1.maxP.y>=b2.maxP.y)):
return True
return False
def boundboxFilter(self,boundbox):
cdef:
int i
int minx,miny,maxx,maxy
list pointList=[]
Boundbox p,b1,b2
#for i in xrange(len(boundbox)):
# pointList.append(boundbox[i])
pointList=boundbox
pointList.sort(cmp=self.__numeric_compare_by_x)
stack=[]
stack.append(pointList[0])
for p in pointList[1:]:
top=len(stack)-1
b1=stack[top]
b2=p
if(not(self.isBoundbox_inside(b1,b2))):
stack.append(b2)
pointList=stack
pointList.sort(cmp=self.__numeric_compare_by_y)
stack=[]
stack.append(pointList[0])
for p in pointList[1:]:
top=len(stack)-1
b1=stack[top]
b2=p
if(not(self.isBoundbox_inside(b1,b2))):
stack.append(b2)
return stack
你可以展示一個更簡單的例子,也許正好兩個矩形,包含和一個被刪除?很難理解這麼複雜的輸入是怎麼回事 – Nicolas78
我的輸入是所有矩形的[minx,miny,maxx,maxy]列表,如圖所示 –
也許你可以嘗試調整[層次結構功能](http: //opencvpython.blogspot.ch/2013/01/contours-5-hierarchy.html)在OpenCV而不是使用自定義算法? – Raoul