pythonopencv_python opencv 绘图

gistfile1.txt

# visualize

colors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 255, 0], [170, 255, 0], [85, 255, 0], [0, 255, 0], \

[0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255], \

[170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85]]

cmap = matplotlib.cm.get_cmap('hsv')

canvas = cv.imread(test_image) # B,G,R order

print 'all_peaks len :'+str(len(all_peaks))

for ii in all_peaks:

print ii

for i in range(18):

rgba = np.array(cmap(1 - i/18. - 1./36))

rgba[0:3] *= 255

for j in range(len(all_peaks[i])):

cv.circle(canvas, all_peaks[i][j][0:2], 4, colors[i], thickness=-1)

to_plot = cv.addWeighted(oriImg, 0.3, canvas, 0.7, 0)

plt.imshow(to_plot[:,:,[2,1,0]])

fig = matplotlib.pyplot.gcf()

fig.set_size_inches(12, 12)

# visualize 2

stickwidth = 4

print 'subset:'+str(subset)

for i in range(17):

for n in range(len(subset)):

index = subset[n][np.array(limbSeq[i])-1]

print 'index:'+str(index)

if -1 in index:

continue

cur_canvas = canvas.copy()

Y = candidate[index.astype(int), 0]

X = candidate[index.astype(int), 1]

print 'X :'+str(X)

print 'Y '+str(Y)

mX = np.mean(X)

mY = np.mean(Y)

print ' mX :'+str( mX )+' mY:'+str(mY)

length = ((X[0] - X[1]) ** 2 + (Y[0] - Y[1]) ** 2) ** 0.5

angle = math.degrees(math.atan2(X[0] - X[1], Y[0] - Y[1]))

print 'length:'+str(length)+' angle: '+str(angle)

polygon = cv.ellipse2Poly((int(mY),int(mX)), (int(length/2), stickwidth), int(angle), 0, 360, 1) # Python: cv2.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta) Parameters:

# center – Center of the arc.

# axes – Half of the size of the ellipse main axes. See the ellipse() for details.

# angle – Rotation angle of the ellipse in degrees. See the ellipse() for details.

# arcStart – Starting angle of the elliptic arc in degrees.

# arcEnd – Ending angle of the elliptic arc in degrees.

# delta – Angle between the subsequent polyline vertices. It defines the approximation accuracy.

# pts – Output vector of polyline vertices.

cv.fillConvexPoly(cur_canvas, polygon, colors[i])

canvas = cv.addWeighted(canvas, 0.4, cur_canvas, 0.6, 0)

print '------'

print '*****'

plt.imshow(canvas[:,:,[2,1,0]])

fig = matplotlib.pyplot.gcf()

fig.set_size_inches(12, 12)

# https://docs.opencv.org/2.4.13.4/modules/core/doc/drawing_functions.html?highlight=ellipse2poly#cv2.ellipse2Poly

2017-10-20 13:18:15屏幕截图.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值