コード例 #1
0
	def test_edge(seq,adding,level):
	    if seq == None: 
		return adding

            dst1=cv.PointPolygonTest(seq,pt.pt,1)
            dst2=cv.PointPolygonTest(seq,pt2.pt,1)
		
            if adding and dst1>0 and dst2>0: 
		return False 
            elif adding and (dst1>0 or dst2>0):
		return False
            elif not adding and (dst1>0 and dst2>0):
		return test_edge(seq.v_next(),adding!=True,level+1)
	    else:
	        return test_edge(seq.h_next(),adding,level+1)
コード例 #2
0
ファイル: corner.py プロジェクト: mroja/eyetracker
 def _append_candidates_from_conts(self, rect, result, nconts, m_d):
     nconts = map(lambda (x, y): (x + rect[0], y + rect[1]), nconts)
     nconts.append(nconts[0])
     nconts.append(nconts[1])
     dir = 0
     a, b = add(nconts[0], nconts[2])
     a, b = add((a, b), nconts[1], 1000)
     conv = cv.PointPolygonTest(nconts, (a / 1002.0, b / 1002.0), 0)
     dir = det(nconts[0], nconts[1], nconts[2])
     if (conv * dir < 0):
         nconts = list(reversed(nconts))
     for i in range(1, len(nconts) - 1):
         if  not point_on_edge(nconts[i], rect) and \
             det(nconts[i - 1], nconts[i], nconts[i + 1]) > 0:
             # direction is ok - it is "convex corner"
             if nconts[i] == (104, 197):
                 pass
             cor = Corner(nconts,
                          i,
                          imgtime=m_d.time,
                          scale_f=m_d.scale_factor)
             cor.black_inside = self.black_inside
             cor.compute_change(self, m_d.img)
             cor.check_color(m_d.imgs[0], m_d.gray_imgs[0])
             if not cor.different: result.append(cor)
コード例 #3
0
ファイル: cvutils.py プロジェクト: akats/crowd_counter
def line_rectangle_intersection(pt11, pt12, rect):
    corners=list()
    corners.append((rect[0], rect[1]))
    corners.append((rect[0]+rect[2], rect[1]))
    corners.append((rect[0]+rect[2], rect[1]+rect[3]))
    corners.append((rect[0], rect[1]+rect[3]))
    corners_np = np.array(corners)
    
    
    points = list()
    for line in zip(corners, corners[1:] + corners[:1]):
        intersection_point = line_intersection(pt11, pt12, line[0], line[1])
        if cv.PointPolygonTest(corners_np, intersection_point, 0) >= 0:
            points.append(intersection_point)
    
    assert(len(points)==2)
    return points[0], points[1]
コード例 #4
0
def get_top(shape, center, theta):
    pt = center
    EPSILON = 1.0
    angle = theta
    scale = 0
    (r_x, r_y, r_w, r_h) = cv.BoundingRect(shape)
    if SCALE_METHOD == AXIS:
        top_pt = center
        best_scale = 1
        while (pt[0] > r_x and pt[0] < r_x + r_w and pt[1] > r_y
               and pt[1] < r_y + r_w):
            print
            (x, y) = pt
            new_x = x + EPSILON * sin(angle)
            new_y = y - EPSILON * cos(angle)
            pt = (new_x, new_y)
            scale += EPSILON
            if cv.PointPolygonTest(shape, pt, 0) > 0:
                top_pt = pt
                best_scale = scale
        return (top_pt, best_scale)
    else:
        return ((r_x + r_w / 2, r_y), max(r_w, r_h))
コード例 #5
0
 def __contains__(self, point):
     return cv.PointPolygonTest(self.boundary_points, point, 0) >= 0
コード例 #6
0
ファイル: run.py プロジェクト: catree/sonic-gesture
cv.MorphologyEx(frameTh, frameClosed, temp, element, cv.CV_MOP_CLOSE)
#cv.Dilate(frameTh, frameClosed, element, 1)

# find contours
cv.Copy(frameClosed, temp)
contours = cv.FindContours(temp, cv.CreateMemStorage(),
    mode=cv.CV_RETR_EXTERNAL, method=cv.CV_CHAIN_APPROX_SIMPLE, offset=(0, 0))

contour_iter = contours

# label the contours
head = left = right = None
blobs = []
while contour_iter:
    blob = Blob(contour_iter)
    if cv.PointPolygonTest(contour_iter, face_center, 0) > 0:
        if head !=  None:
            print("ERROR: 2 heads found")
            exit(1)
        head = blob
    else:
        if blob.area > MINBLOB:
            blobs.append(blob)

    contour_iter = contour_iter.h_next()

blobs.sort(cmp=lambda x,y: cmp(x.area, y.area))
blobs = blobs[-2:]
blobs.sort(cmp=lambda x,y: cmp(x.center[0], y.center[0]))

n = len(blobs)