def draw_images(self, frame, hsv, mask_ball, mask_arena, arena_center, arena_ring_radius=None):
self.draw_history(frame, 'ball')
self.draw_history(frame, 'arena')
if arena_ring_radius is not None:
cv2.circle(frame, arena_center, arena_ring_radius, (0, 128, 255), 2)
return frame
#rgbs = cv2.split(frame)
#hsvs = cv2.split(hsv)
#cv2.imshow("Hue", hsvs[0])
#cv2.imshow("Mask ball", mask_ball)
#cv2.imshow("Mask arena", mask_arena)
#cv2.imshow("Frame", frame)
#cv2.waitKey(1)
#cv2.imshow("Red", rgbs[0])
#cv2.imshow("Green", rgbs[1])
#cv2.imshow("Blue", rgbs[2])
#cv2.imshow("Saturation", hsvs[1])
#cv2.imshow("Value", hsvs[2])
#cv2.waitKey(1)
python类circle()的实例源码
def update(dummy=None):
if seed_pt is None:
cv2.imshow('floodfill', img)
return
flooded = img.copy()
mask[:] = 0
lo = cv2.getTrackbarPos('lo', 'floodfill')
hi = cv2.getTrackbarPos('hi', 'floodfill')
flags = connectivity
if fixed_range:
flags |= cv2.FLOODFILL_FIXED_RANGE
cv2.floodFill(flooded, mask, seed_pt, (255, 255, 255), (lo,)*3, (hi,)*3, flags)
cv2.circle(flooded, seed_pt, 2, (0, 0, 255), -1)
cv2.imshow('floodfill', flooded)
def draw_flow(img, flow, step=16):
h, w = img.shape[:2]
y, x = np.mgrid[step/2:h:step, step/2:w:step].reshape(2, -1).astype(int) # ????????????????????????16?reshape?2??array
fx, fy = flow[y, x].T # ???????????????
lines = np.vstack([x, y, x+fx, y+fy]).T.reshape(-1, 2, 2) # ????????????2*2???
lines = np.int32(lines + 0.5) # ????????????
vis = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
cv2.polylines(vis, lines, 0, (0, 255, 0)) # ???????????????
for (x1, y1), (x2, y2) in lines:
cv2.circle(vis, (x1, y1), 1, (0, 255, 0), -1) # ???????????????????
return vis
def draw_circles(self):
"""
Draw a circle for each contour in self.candidates
"""
# Just false positives
if len(self.candidates) < 4:
return
for con in self.candidates:
if con.width:
cv2.circle(self.image,
(con.cX, con.cY),
int(con.width/2),
(255, 255, 255),
2)
def draw_correspondences(img, dstpoints, projpts):
display = img.copy()
dstpoints = norm2pix(img.shape, dstpoints, True)
projpts = norm2pix(img.shape, projpts, True)
for pts, color in [(projpts, (255, 0, 0)),
(dstpoints, (0, 0, 255))]:
for point in pts:
cv2.circle(display, fltp(point), 3, color, -1, cv2.LINE_AA)
for point_a, point_b in zip(projpts, dstpoints):
cv2.line(display, fltp(point_a), fltp(point_b),
(255, 255, 255), 1, cv2.LINE_AA)
return display
def visualize_contours(name, small, cinfo_list):
regions = np.zeros_like(small)
for j, cinfo in enumerate(cinfo_list):
cv2.drawContours(regions, [cinfo.contour], 0,
CCOLORS[j % len(CCOLORS)], -1)
mask = (regions.max(axis=2) != 0)
display = small.copy()
display[mask] = (display[mask]/2) + (regions[mask]/2)
for j, cinfo in enumerate(cinfo_list):
color = CCOLORS[j % len(CCOLORS)]
color = tuple([c/4 for c in color])
cv2.circle(display, fltp(cinfo.center), 3,
(255, 255, 255), 1, cv2.LINE_AA)
cv2.line(display, fltp(cinfo.point0), fltp(cinfo.point1),
(255, 255, 255), 1, cv2.LINE_AA)
debug_show(name, 1, 'contours', display)
def visualize_span_points(name, small, span_points, corners):
display = small.copy()
for i, points in enumerate(span_points):
points = norm2pix(small.shape, points, False)
mean, small_evec = cv2.PCACompute(points.reshape((-1, 2)),
None,
maxComponents=1)
dps = np.dot(points.reshape((-1, 2)), small_evec.reshape((2, 1)))
dpm = np.dot(mean.flatten(), small_evec.flatten())
point0 = mean + small_evec * (dps.min()-dpm)
point1 = mean + small_evec * (dps.max()-dpm)
for point in points:
cv2.circle(display, fltp(point), 3,
CCOLORS[i % len(CCOLORS)], -1, cv2.LINE_AA)
cv2.line(display, fltp(point0), fltp(point1),
(255, 255, 255), 1, cv2.LINE_AA)
cv2.polylines(display, [norm2pix(small.shape, corners, True)],
True, (255, 255, 255))
debug_show(name, 3, 'span points', display)
def draw_joints(test_image, joints, save_image):
image = cv2.imread(test_image)
joints = np.vstack((joints, (joints[8, :] + joints[11, :])/2))
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 2)
# draw torso in yellow lines
torso = [[0, 1], [1, 14], [2, 14], [5, 14]]
for item in torso:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 2)
# draw left part in pink lines
lpart = [[1, 5], [5, 6], [6, 7], [5, 14], [14, 11], [11, 12], [12, 13]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 2)
# draw right part in blue lines
rpart = [[1, 2], [2, 3], [3, 4], [2, 14], [14, 8], [8, 9], [9, 10]]
for item in rpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 2)
cv2.imwrite(save_image, image)
def draw_joints_15(test_image, joints, save_image):
image = cv2.imread(test_image)
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 1)
# draw torso in yellow lines
torso = [[0, 1], [0, 14], [5, 10]]
for item in torso:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 1)
# draw left part in pink lines
lpart = [[14, 13], [13, 12], [12, 11], [13, 10], [10, 9], [9, 8]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 1)
# draw right part in blue lines
rpart = [[1, 2], [2, 3], [3, 4], [2, 5], [5, 6], [6, 7]]
for item in rpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 1)
cv2.imwrite(save_image, image)
def draw_joints_13(test_image, joints, save_image):
image = cv2.imread(test_image)
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 2)
# draw torso in yellow lines
torso = [[0, 1], [1, 8]]
for item in torso:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 2)
# draw left part in pink lines
lpart = [[1, 3], [3, 5], [5, 7], [3, 8], [8, 10], [10, 12]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 2)
# draw right part in blue lines
rpart = [[1, 2], [2, 4], [4, 6], [2, 8], [8, 9], [9, 11]]
for item in rpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 2)
cv2.imwrite(save_image, image)
def draw_joints_17(test_image, joints, save_image):
image = cv2.imread(test_image)
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 2)
# draw head in yellow lines
head = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6]]
for item in head:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 2)
# draw upper part in pink lines
upart = [[5, 6], [5, 7], [6, 8], [7, 9], [8, 10], [5, 11], [6, 12], [11, 12]]
for item in upart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 2)
# draw lower part in blue lines
lpart = [[11, 13], [12, 14], [13, 15], [14, 16]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 2)
cv2.imwrite(save_image, image)
def draw_gt_market(test_image, joints, save_image):
image = cv2.imread(test_image)
# draw joints in green spots
for j in xrange(len(joints) / 2):
cv2.circle(image, (joints[j * 2], joints[j * 2 + 1]), 2, (0, 255, 0), 1)
# draw torso in yellow lines
p1 = [0, 0, 5]
p2 = [1, 14, 10]
for j in xrange(len(p1)):
cv2.line(image, (joints[p1[j] * 2], joints[p1[j] * 2 + 1]), (joints[p2[j] * 2], joints[p2[j] * 2 + 1]),
(0, 255, 255), 1)
# draw left part in pink lines
p1 = [14, 13, 12, 13, 10, 9]
p2 = [13, 12, 11, 10, 9, 8]
for j in xrange(len(p1)):
cv2.line(image, (joints[p1[j] * 2], joints[p1[j] * 2 + 1]), (joints[p2[j] * 2], joints[p2[j] * 2 + 1]),
(255, 0, 255), 1)
# draw right part in blue lines
p1 = [1, 2, 3, 2, 5, 6]
p2 = [2, 3, 4, 5, 6, 7]
for j in xrange(len(p1)):
cv2.line(image, (joints[p1[j] * 2], joints[p1[j] * 2 + 1]), (joints[p2[j] * 2], joints[p2[j] * 2 + 1]),
(255, 0, 0), 1)
cv2.imwrite(save_image, image)
def draw_joints(test_image, joints, save_image):
image = cv2.imread(test_image)
joints = np.vstack((joints, (joints[8, :] + joints[11, :])/2))
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 2)
# draw torso in yellow lines
torso = [[0, 1], [1, 14], [2, 14], [5, 14]]
for item in torso:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 2)
# draw left part in pink lines
lpart = [[1, 5], [5, 6], [6, 7], [5, 14], [14, 11], [11, 12], [12, 13]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 2)
# draw right part in blue lines
rpart = [[1, 2], [2, 3], [3, 4], [2, 14], [14, 8], [8, 9], [9, 10]]
for item in rpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 2)
cv2.imwrite(save_image, image)
def draw_joints_15(test_image, joints, save_image):
image = cv2.imread(test_image)
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 1)
# draw torso in yellow lines
torso = [[0, 1], [0, 14], [5, 10]]
for item in torso:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 1)
# draw left part in pink lines
lpart = [[14, 13], [13, 12], [12, 11], [13, 10], [10, 9], [9, 8]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 1)
# draw right part in blue lines
rpart = [[1, 2], [2, 3], [3, 4], [2, 5], [5, 6], [6, 7]]
for item in rpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 1)
cv2.imwrite(save_image, image)
def draw_joints_17(test_image, joints, save_image):
image = cv2.imread(test_image)
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 2)
# draw head in yellow lines
head = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6]]
for item in head:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 2)
# draw upper part in pink lines
upart = [[5, 6], [5, 7], [6, 8], [7, 9], [8, 10], [5, 11], [6, 12], [11, 12]]
for item in upart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 2)
# draw lower part in blue lines
lpart = [[11, 13], [12, 14], [13, 15], [14, 16]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 2)
cv2.imwrite(save_image, image)
def draw_joints_16(test_image, joints, save_image):
image = cv2.imread(test_image)
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 2)
# draw torso in yellow lines
torso = [[9, 8], [8, 7], [7, 6]]
for item in torso:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 2)
# draw left part in pink lines
lpart = [[8, 13], [13, 14], [14, 15], [13, 6], [6, 3], [3, 4], [4, 5]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 2)
# draw right part in blue lines
rpart = [[8, 12], [12, 11], [11, 10], [12, 6], [6, 2], [2, 1], [1, 0]]
for item in rpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 2)
cv2.imwrite(save_image, image)
def draw_gt_market(test_image, joints, save_image):
image = cv2.imread(test_image)
# draw joints in green spots
for j in xrange(len(joints) / 2):
cv2.circle(image, (joints[j * 2], joints[j * 2 + 1]), 2, (0, 255, 0), 1)
# draw torso in yellow lines
p1 = [0, 0, 5]
p2 = [1, 14, 10]
for j in xrange(len(p1)):
cv2.line(image, (joints[p1[j] * 2], joints[p1[j] * 2 + 1]), (joints[p2[j] * 2], joints[p2[j] * 2 + 1]),
(0, 255, 255), 1)
# draw left part in pink lines
p1 = [14, 13, 12, 13, 10, 9]
p2 = [13, 12, 11, 10, 9, 8]
for j in xrange(len(p1)):
cv2.line(image, (joints[p1[j] * 2], joints[p1[j] * 2 + 1]), (joints[p2[j] * 2], joints[p2[j] * 2 + 1]),
(255, 0, 255), 1)
# draw right part in blue lines
p1 = [1, 2, 3, 2, 5, 6]
p2 = [2, 3, 4, 5, 6, 7]
for j in xrange(len(p1)):
cv2.line(image, (joints[p1[j] * 2], joints[p1[j] * 2 + 1]), (joints[p2[j] * 2], joints[p2[j] * 2 + 1]),
(255, 0, 0), 1)
cv2.imwrite(save_image, image)
def draw_joints_13(test_image, joints, save_image):
image = cv2.imread(test_image)
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 2)
# draw torso in yellow lines
torso = [[0, 1], [1, 8]]
for item in torso:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 2)
# draw left part in pink lines
lpart = [[1, 3], [3, 5], [5, 7], [3, 8], [8, 10], [10, 12]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 2)
# draw right part in blue lines
rpart = [[1, 2], [2, 4], [4, 6], [2, 8], [8, 9], [9, 11]]
for item in rpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 2)
cv2.imwrite(save_image, image)
def draw_joints_17(test_image, joints, save_image):
image = cv2.imread(test_image)
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 2)
# draw head in yellow lines
head = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6]]
for item in head:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 2)
# draw upper part in pink lines
upart = [[5, 6], [5, 7], [6, 8], [7, 9], [8, 10], [5, 11], [6, 12], [11, 12]]
for item in upart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 2)
# draw lower part in blue lines
lpart = [[11, 13], [12, 14], [13, 15], [14, 16]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 2)
cv2.imwrite(save_image, image)
def draw_joints_16(test_image, joints, save_image):
image = cv2.imread(test_image)
# bounding box
bbox = [min(joints[:, 0]), min(joints[:, 1]), max(joints[:, 0]), max(joints[:, 1])]
# draw bounding box in red rectangle
cv2.rectangle(image, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)
# draw joints in green spots
for j in xrange(len(joints)):
cv2.circle(image, (joints[j, 0], joints[j, 1]), 5, (0, 255, 0), 2)
# draw torso in yellow lines
torso = [[9, 8], [8, 7], [7, 6]]
for item in torso:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (0, 255, 255), 2)
# draw left part in pink lines
lpart = [[8, 13], [13, 14], [14, 15], [13, 6], [6, 3], [3, 4], [4, 5]]
for item in lpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 255), 2)
# draw right part in blue lines
rpart = [[8, 12], [12, 11], [11, 10], [12, 6], [6, 2], [2, 1], [1, 0]]
for item in rpart:
cv2.line(image, (joints[item[0], 0], joints[item[0], 1]), (joints[item[1], 0], joints[item[1], 1]), (255, 0, 0), 2)
cv2.imwrite(save_image, image)