本文整理汇总了Python中cv2.circle方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.circle方法的具体用法?Python cv2.circle怎么用?Python cv2.circle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.circle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: blob
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def blob(x):
"""Given an Nx3 matrix of blob positions and size,
create N img_size x img_size images, each with a blob drawn on
them given by the value in each row of x
One row of x = [x,y,radius]."""
y = np.zeros((x.shape[0], img_size, img_size))
for i, particle in enumerate(x):
rr, cc = skimage.draw.circle(
particle[0], particle[1], max(particle[2], 1), shape=(img_size, img_size)
)
y[i, rr, cc] = 1
return y
#%%
# names (this is just for reference for the moment!)
示例2: ProcessFrame
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def ProcessFrame(self, frame):
# segment arm region
segment = self.SegmentArm(frame)
# make a copy of the segmented image to draw on
draw = cv2.cvtColor(segment, cv2.COLOR_GRAY2RGB)
# draw some helpers for correctly placing hand
cv2.circle(draw,(self.imgWidth/2,self.imgHeight/2),3,[255,102,0],2)
cv2.rectangle(draw, (self.imgWidth/3,self.imgHeight/3), (self.imgWidth*2/3, self.imgHeight*2/3), [255,102,0],2)
# find the hull of the segmented area, and based on that find the
# convexity defects
[contours,defects] = self.FindHullDefects(segment)
# detect the number of fingers depending on the contours and convexity defects
# draw defects that belong to fingers green, others red
[nofingers,draw] = self.DetectNumberFingers(contours, defects, draw)
# print number of fingers on image
cv2.putText(draw, str(nofingers), (30,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255))
return draw
示例3: update
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def update(self, radarData):
self.img = np.zeros((self.height, self.width, self.channels), np.uint8)
cv2.line(self.img, (10, 0), (self.width/2 - 5, self.height), (100, 255, 255))
cv2.line(self.img, (self.width - 10, 0), (self.width/2 + 5, self.height), (100, 255, 255))
for track_number in range(1, 65):
if str(track_number)+'_track_range' in radarData:
track_range = radarData[str(track_number)+'_track_range']
track_angle = (float(radarData[str(track_number)+'_track_angle'])+90.0)*math.pi/180
x_pos = math.cos(track_angle)*track_range*4
y_pos = math.sin(track_angle)*track_range*4
cv2.circle(self.img, (self.width/2 + int(x_pos), self.height - int(y_pos) - 10), 5, (255, 255, 255))
#cv2.putText(self.img, str(track_number),
# (self.width/2 + int(x_pos)-2, self.height - int(y_pos) - 10), self.font, 1, (255,255,255), 2)
cv2.imshow("Radar", self.img)
cv2.waitKey(2)
示例4: mark_hand_center
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def mark_hand_center(frame_in,cont):
max_d=0
pt=(0,0)
x,y,w,h = cv2.boundingRect(cont)
for ind_y in xrange(int(y+0.3*h),int(y+0.8*h)): #around 0.25 to 0.6 region of height (Faster calculation with ok results)
for ind_x in xrange(int(x+0.3*w),int(x+0.6*w)): #around 0.3 to 0.6 region of width (Faster calculation with ok results)
dist= cv2.pointPolygonTest(cont,(ind_x,ind_y),True)
if(dist>max_d):
max_d=dist
pt=(ind_x,ind_y)
if(max_d>radius_thresh*frame_in.shape[1]):
thresh_score=True
cv2.circle(frame_in,pt,int(max_d),(255,0,0),2)
else:
thresh_score=False
return frame_in,pt,max_d,thresh_score
# 6. Find and display gesture
示例5: draw_humans
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def draw_humans(npimg, humans, imgcopy=False):
if imgcopy:
npimg = np.copy(npimg)
image_h, image_w = npimg.shape[:2]
centers = {}
for human in humans:
# draw point
for i in range(common.CocoPart.Background.value):
if i not in human.body_parts.keys():
continue
body_part = human.body_parts[i]
center = (int(body_part.x * image_w + 0.5), int(body_part.y * image_h + 0.5))
centers[i] = center
cv2.circle(npimg, center, 3, common.CocoColors[i], thickness=3, lineType=8, shift=0)
# draw line
for pair_order, pair in enumerate(common.CocoPairsRender):
if pair[0] not in human.body_parts.keys() or pair[1] not in human.body_parts.keys():
continue
npimg = cv2.line(npimg, centers[pair[0]], centers[pair[1]], common.CocoColors[pair_order], 3)
return npimg
示例6: draw_limbs
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def draw_limbs(image, pose_2d, visible):
"""Draw the 2D pose without the occluded/not visible joints."""
_COLORS = [
[0, 0, 255], [0, 170, 255], [0, 255, 170], [0, 255, 0],
[170, 255, 0], [255, 170, 0], [255, 0, 0], [255, 0, 170],
[170, 0, 255]
]
_LIMBS = np.array([0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9,
9, 10, 11, 12, 12, 13]).reshape((-1, 2))
_NORMALISATION_FACTOR = int(math.floor(math.sqrt(image.shape[0] * image.shape[1] / NORMALISATION_COEFFICIENT)))
for oid in range(pose_2d.shape[0]):
for lid, (p0, p1) in enumerate(_LIMBS):
if not (visible[oid][p0] and visible[oid][p1]):
continue
y0, x0 = pose_2d[oid][p0]
y1, x1 = pose_2d[oid][p1]
cv2.circle(image, (x0, y0), JOINT_DRAW_SIZE *_NORMALISATION_FACTOR , _COLORS[lid], -1)
cv2.circle(image, (x1, y1), JOINT_DRAW_SIZE*_NORMALISATION_FACTOR , _COLORS[lid], -1)
cv2.line(image, (x0, y0), (x1, y1),
_COLORS[lid], LIMB_DRAW_SIZE*_NORMALISATION_FACTOR , 16)
示例7: plot_3d_pts
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def plot_3d_pts(img, pts, center, calib_file=None, cam_to_img=None, relative=False, constraint_idx=None):
if calib_file is not None:
cam_to_img = get_calibration_cam_to_image(calib_file)
for pt in pts:
if relative:
pt = [i + center[j] for j,i in enumerate(pt)] # more pythonic
point = project_3d_pt(pt, cam_to_img)
color = cv_colors.RED.value
if constraint_idx is not None:
color = constraint_to_color(constraint_idx)
cv2.circle(img, (point[0], point[1]), 3, color, thickness=-1)
示例8: annotate
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def annotate(self, img):
# paint annotations on the image
for i1 in range(len(self.kpus)):
u1, v1 = int(round(self.kpus[i1][0])), int(round(self.kpus[i1][1]))
if self.pts[i1] is not None:
if len(self.pts[i1].frames) >= 5:
cv2.circle(img, (u1, v1), color=(0,255,0), radius=3)
else:
cv2.circle(img, (u1, v1), color=(0,128,0), radius=3)
# draw the trail
pts = []
lfid = None
for f, idx in zip(self.pts[i1].frames[-9:][::-1], self.pts[i1].idxs[-9:][::-1]):
if lfid is not None and lfid-1 != f.id:
break
pts.append(tuple(map(lambda x: int(round(x)), f.kpus[idx])))
lfid = f.id
if len(pts) >= 2:
cv2.polylines(img, np.array([pts], dtype=np.int32), False, myjet[len(pts)]*255, thickness=1, lineType=16)
else:
cv2.circle(img, (u1, v1), color=(0,0,0), radius=3)
return img
# inverse of intrinsics matrix
示例9: load_shapes
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def load_shapes(self, count, height, width):
"""Generate the requested number of synthetic images.
count: number of images to generate.
height, width: the size of the generated images.
"""
# Add classes
self.add_class("shapes", 1, "square")
self.add_class("shapes", 2, "circle")
self.add_class("shapes", 3, "triangle")
# Add images
# Generate random specifications of images (i.e. color and
# list of shapes sizes and locations). This is more compact than
# actual images. Images are generated on the fly in load_image().
for i in range(count):
bg_color, shapes = self.random_image(height, width)
self.add_image("shapes", image_id=i, path=None,
width=width, height=height,
bg_color=bg_color, shapes=shapes)
示例10: draw_shape
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def draw_shape(self, image, shape, dims, color):
"""Draws a shape from the given specs."""
# Get the center x, y and the size s
x, y, s = dims
if shape == 'square':
image = cv2.rectangle(image, (x - s, y - s),
(x + s, y + s), color, -1)
elif shape == "circle":
image = cv2.circle(image, (x, y), s, color, -1)
elif shape == "triangle":
points = np.array([[(x, y - s),
(x - s / math.sin(math.radians(60)), y + s),
(x + s / math.sin(math.radians(60)), y + s),
]], dtype=np.int32)
image = cv2.fillPoly(image, points, color)
return image
示例11: random_shape
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def random_shape(self, height, width):
"""Generates specifications of a random shape that lies within
the given height and width boundaries.
Returns a tuple of three valus:
* The shape name (square, circle, ...)
* Shape color: a tuple of 3 values, RGB.
* Shape dimensions: A tuple of values that define the shape size
and location. Differs per shape type.
"""
# Shape
shape = random.choice(["square", "circle", "triangle"])
# Color
color = tuple([random.randint(0, 255) for _ in range(3)])
# Center x, y
buffer = 20
y = random.randint(buffer, height - buffer - 1)
x = random.randint(buffer, width - buffer - 1)
# Size
s = random.randint(buffer, height // 4)
return shape, color, (x, y, s)
示例12: update
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def update(_=None):
noise = cv2.getTrackbarPos('noise', 'fit line')
n = cv2.getTrackbarPos('point n', 'fit line')
r = cv2.getTrackbarPos('outlier %', 'fit line') / 100.0
outn = int(n*r)
p0, p1 = (90, 80), (w-90, h-80)
img = np.zeros((h, w, 3), np.uint8)
cv2.line(img, toint(p0), toint(p1), (0, 255, 0))
if n > 0:
line_points = sample_line(p0, p1, n-outn, noise)
outliers = np.random.rand(outn, 2) * (w, h)
points = np.vstack([line_points, outliers])
for p in line_points:
cv2.circle(img, toint(p), 2, (255, 255, 255), -1)
for p in outliers:
cv2.circle(img, toint(p), 2, (64, 64, 255), -1)
func = getattr(cv2, cur_func_name)
vx, vy, cx, cy = cv2.fitLine(np.float32(points), func, 0, 0.01, 0.01)
cv2.line(img, (int(cx-vx*w), int(cy-vy*w)), (int(cx+vx*w), int(cy+vy*w)), (0, 0, 255))
draw_str(img, (20, 20), cur_func_name)
cv2.imshow('fit line', img)
示例13: drawMatch
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def drawMatch(img0,img1,src,tgt,color='b'):
if len(img0.shape)==2:
img0=np.expand_dims(img0,2)
if len(img1.shape)==2:
img1=np.expand_dims(img1,2)
h,w = img0.shape[0],img0.shape[1]
img = np.zeros([2*h,w,3])
img[:h,:,:] = img0
img[h:,:,:] = img1
n = len(src)
if color == 'b':
color=(255,0,0)
else:
color=(0,255,0)
for i in range(n):
cv2.circle(img, (int(src[i,0]), int(src[i,1])), 3,color,-1)
cv2.circle(img, (int(tgt[i,0]), int(tgt[i,1])+h), 3,color,-1)
cv2.line(img, (int(src[i,0]),int(src[i,1])),(int(tgt[i,0]),int(tgt[i,1])+h),color,1)
return img
示例14: visualize_joints
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def visualize_joints(bone_list, focus):
m = np.zeros((424, 600, 3))
m.astype(np.uint8)
for bone in bone_list:
p1x = bone[0][0]
p1y = bone[0][1]
p1z = bone[0][2] + 400
p2x = bone[1][0]
p2y = bone[1][1]
p2z = bone[1][2] + 400
p1 = (
int(p1x * focus / p1z + 300.0), int(-p1y * focus / p1z + 204.0))
p2 = (int(p2x * focus / p2z + 300.0), int(-p2y * focus / p2z + 204.0))
if inside_image(p1[0], p1[1]) and inside_image(p2[0], p2[1]):
cv.line(m, p1, p2, (255, 0, 0), 2)
cv.circle(m, p1, 2, (0, 255, 255), -1)
cv.circle(m, p2, 2, (0, 255, 255), -1)
return m
示例15: visualize_joints2
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import circle [as 别名]
def visualize_joints2(bone_list, focus):
m = np.zeros((424, 600, 3))
m.astype(np.uint8)
for bone in bone_list:
p1x = bone[0][0]
p1y = bone[0][1]
p1z = bone[0][2] + 400
p2x = bone[1][0]
p2y = bone[1][1]
p2z = bone[1][2] + 400
p1 = (
int(p1x * focus / p1z + 300.0), int(-p1y * focus / p1z + 204.0))
p2 = (int(p2x * focus / p2z + 300.0), int(-p2y * focus / p2z + 204.0))
if inside_image(p1[0], p1[1]) and inside_image(p2[0], p2[1]):
cv.line(m, p1, p2, (255, 0, 0), 2)
cv.circle(m, p1, 2, (0, 255, 255), -1)
cv.circle(m, p2, 2, (0, 255, 255), -1)
return m