def find_polygons(self, thresh=0, erode_value=0, dilate_value=0, angle=0):
        self.frames = []
        frame = self.source_frame
        # crop(frame, 150, 150, 300, 300)
        # display original
        # timg = rotate(clone(self.source_frame), angle)
        # self.frames.append(timg)
        self.frames.append(frame)
        gsrc = grayspace(frame)
        gsrc = erode(gsrc, erode_value)
        gsrc = dilate(gsrc, dilate_value)
        gsrc = threshold(gsrc, thresh)

        self.frames.append(colorspace(gsrc))
        # contour the threshold source
        _nc, contours = contour(gsrc)
        if contours:
            # display the contours
            csrc = clone(colorspace(gsrc))
#            draw_contour_list(csrc, contours)

            # approximate and draw polygons from contours
            polygons, br = get_polygons(contours)

            # draw_rectangles(csrc, polygons)
            draw_polygons(csrc, polygons)
            self.frames.append(csrc)
            return br, polygons
    def find_polygons(self, thresh=0, erode_value=0, dilate_value=0, angle=0):
        self.frames = []
        frame = self.source_frame
        # crop(frame, 150, 150, 300, 300)
        # display original
        # timg = rotate(clone(self.source_frame), angle)
        # self.frames.append(timg)
        self.frames.append(frame)
        gsrc = grayspace(frame)
        gsrc = erode(gsrc, erode_value)
        gsrc = dilate(gsrc, dilate_value)
        gsrc = threshold(gsrc, thresh)

        self.frames.append(colorspace(gsrc))
        # contour the threshold source
        _nc, contours = contour(gsrc)
        if contours:
            # display the contours
            csrc = clone(colorspace(gsrc))
            #            draw_contour_list(csrc, contours)

            # approximate and draw polygons from contours
            polygons, br = get_polygons(contours)

            # draw_rectangles(csrc, polygons)
            draw_polygons(csrc, polygons)
            self.frames.append(csrc)
            return br, polygons
    def process(self, thresh=0, erode_value=0, dilate_value=0, angle=0):
        '''
   
        '''

        self.frames = []
        frame = self.source_frame
        # crop(frame, 150, 150, 300, 300)
        # display original
        # timg = rotate(clone(self.source_frame), angle)
        # self.frames.append(timg)
        self.frames.append(frame)
        gsrc = grayspace(frame)
        gsrc = erode(gsrc, erode_value)
        gsrc = dilate(gsrc, dilate_value)
        gsrc = threshold(gsrc, thresh)

        self.frames.append(colorspace(gsrc))
        lsrc, ls = lines(gsrc, thresh=thresh)
        self.frames.append(lsrc)

        vert = []
        horz = []
        for li in ls:
            # find vert
            tol = 5
            if abs(li[0].x - li[1].x) < tol:
                #                print 'vert', ((li[0].x + li[1].x) ** 2 + (li[0].y + li[1].y) ** 2) ** 0.5
                vert.append(li)
            elif abs(li[0].y - li[1].y) < tol:
                #                print 'hor', ((li[0].x + li[1].x) ** 2 + (li[0].y + li[1].y) ** 2) ** 0.5
                horz.append(li)

        hdist = []
        for hi in horz:
            for hj in horz:
                hdist.append(
                    max([
                        abs(hi[0].y - hj[0].y),
                        abs(hi[0].y - hj[1].y),
                        abs(hi[1].y - hj[1].y),
                        abs(hi[1].y - hj[0].y)
                    ]))
        vdist = []
        for vi in vert:
            for vj in vert:
                vdist.append(
                    max([
                        abs(vi[0].x - vj[0].x),
                        abs(vi[0].x - vj[1].x),
                        abs(vi[1].x - vj[1].x),
                        abs(vi[1].x - vj[0].x)
                    ]))

        return hdist, vdist
    def process(self, thresh=0, erode_value=0, dilate_value=0, angle=0):
        '''
   
        '''

        self.frames = []
        frame = self.source_frame
        # crop(frame, 150, 150, 300, 300)
        # display original
        # timg = rotate(clone(self.source_frame), angle)
        # self.frames.append(timg)
        self.frames.append(frame)
        gsrc = grayspace(frame)
        gsrc = erode(gsrc, erode_value)
        gsrc = dilate(gsrc, dilate_value)
        gsrc = threshold(gsrc, thresh)

        self.frames.append(colorspace(gsrc))
        lsrc, ls = lines(gsrc, thresh=thresh)
        self.frames.append(lsrc)

        vert = []
        horz = []
        for li in ls:
            # find vert
            tol = 5
            if abs(li[0].x - li[1].x) < tol:
#                print 'vert', ((li[0].x + li[1].x) ** 2 + (li[0].y + li[1].y) ** 2) ** 0.5
                vert.append(li)
            elif abs(li[0].y - li[1].y) < tol:
#                print 'hor', ((li[0].x + li[1].x) ** 2 + (li[0].y + li[1].y) ** 2) ** 0.5
                horz.append(li)

        hdist = []
        for hi in horz:
            for hj in horz:
                hdist.append(max([abs(hi[0].y - hj[0].y),
                  abs(hi[0].y - hj[1].y),
                  abs(hi[1].y - hj[1].y),
                  abs(hi[1].y - hj[0].y)]))
        vdist = []
        for vi in vert:
            for vj in vert:
                vdist.append(max([abs(vi[0].x - vj[0].x),
                  abs(vi[0].x - vj[1].x),
                  abs(vi[1].x - vj[1].x),
                  abs(vi[1].x - vj[0].x)]))

        return hdist, vdist