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