Esempio n. 1
0
def find_convex_hull(ctx):
	defects, defect_array = False, False
	i,x,y,dist = 0,0,0,0
	ctx.hull = False


	if type(ctx.contour) != 'numpy.ndarray':
		return

	#ctx.hull = cv.cvConvexHull2(ctx.contour, ctx.hull_st, cv.CV_CLOCKWISE, 0)
	cv2.convexHull(ctx.contour, ctx.hull_st, 1, ctx.hull)

	#Python: cv2.convexHull(points[, hull[, clockwise[, returnPoints]]])  hull
	#C: CvSeq* cvConvexHull2(const CvArr* input, void* hull_storage=NULL, int orientation=CV_CLOCKWISE, int return_points=0 )


	if ctx.hull:
		ctx.contour = toIpl(ctx.contour)
		defects = cv2.cv.ConvexityDefects(ctx.contour, ctx.hull, ctx.defects_st)
		#defects = cv.cvConvexityDefects(ctx.contour, ctx.hull, ctx.defects_st)

		#C++: void convexityDefects(InputArray contour, InputArray convexhull, OutputArray convexityDefects)
		#Python: cv2.convexityDefects(contour, convexhull[, convexityDefects])  convexityDefects

		if defects and defects.total:
			defect_array = calloc(defects.total, sizeof(cv.cvConvexityDefect))
			cv.cvCvtSeqToArray(defects, defect_array, cv.CV_WHOLE_SEQ)

			for i in NUM_DEFECTS:
				x += i.depth_point.x
				y += i.depth_point.y
				ctx.defects[i] = cv.cvPoint(i.depth_point.x, i.depth_point.y)

			x /= defects.total
			y /= defects.total
		ctx.num_defects = defects.total
		ctx.hand_center = cv.cvPoint(x,y)

		for i in defects.total:
			d = (x - i.depth_point.x) * (x - i.depth_point.x) + (y - i.depth_point.y) * (y - i.depth_point.y)
			dist += sqrt(d)

		ctx.hand_radius = dist / defects.total
		del defect_array
Esempio n. 2
0
    def ellipse(self, dx, dy, width, height, color = (0, 255, 0), border = -1, line = 8):
        """Draw a ellipse on image"""
        rotation = 0
        start_angle = 0
        stop_angle = 360
        shift = 0

        cv.Ellipse(self.frame,
            cv.cvPoint (dx, dy),
            cv.cvSize(width, height),
            rotation, start_angle, stop_angle, color, border, line, shift)
Esempio n. 3
0
    def ellipse(self,
                dx,
                dy,
                width,
                height,
                color=(0, 255, 0),
                border=-1,
                line=8):
        """Draw a ellipse on image"""
        rotation = 0
        start_angle = 0
        stop_angle = 360
        shift = 0

        cv.Ellipse(self.frame, cv.cvPoint(dx, dy), cv.cvSize(width,
                                                             height), rotation,
                   start_angle, stop_angle, color, border, line, shift)
Esempio n. 4
0
def display(ctx):
	i = False

	if ctx.num_fingers == NUM_FINGERS:
		if SHOW_HAND_CONTOUR:
			cv.cvDrawContours(ctx.image, ctx.contour, cv.CV_RGB(0,0,255), cv.CV_RGB(0,255,0), 0, 1, cv.CV_AA, cv.cvPoint(0,0))
		cv.cvCircle(ctx.image, ctx.hand_center, 5, cv.CV_RGB(255,0,255), 1, CV_AA,0)
		cv.cvCircle(ctx.image, ctx.hand_center, ctx.hand_radius, cv.CV_RGB(255,0,0), 1, CV_AA, 0)

		for i in ctx.num_fingers:
			cv.cvCircle(ctx.image, ctx.fingers[i], 10, cv.CV_RGB(0,255,0), 3, cv.CV_AA, 0)
			cv.cvLine(ctx.image, ctx.hand_center, ctx.fingers[i], cv.CV_RGB(255,255,0), 1, cv.CV_AA, 0)

		for i in ctx.num_defects:
			cv.cvCircle(ctx.image, ctx.defects[i], 2, cv.CV_RGB(200,200,200), 2, cv.CV_AA, 0)

	ctx.image = toNumpy(ctx.image)
	cv2.imshow("output", ctx.image)
	ctx.thr_image = toNumpy(ctx.thr_image)
	cv2.imshow("thresholded", ctx.thr_image)