gpt4 book ai didi

python - 如何使用drawcontours为给定坐标绘制徒手线?

转载 作者:行者123 更新时间:2023-12-02 17:30:26 25 4
gpt4 key购买 nike

在图像上,我正在尝试为 json 文件中的给定注释数据绘制徒手线。应以坐标为输入来绘制线,并以徒手线返回图像。

import numpy as np
im = np.zeros([800, 1216],np.uint8)

points = [
[405.49313, 141.8587],[444.5172, 135.35468],
[444.5172, 135.35468],[ 509.44876, 128.50587],
[509.44876, 128.50587],[ 541.78784, 127.92772],
[541.78784, 127.92772],[ 561.9265, 129.86807],
[561.9265, 129.86807],[ 580.7606, 130.36917],
[580.7606, 130.36917],[ 605.0242, 127.64725],
[605.0242, 127.64725],[ 623.9638, 125.8712],
[623.9638, 125.8712],[ 638.4798, 122.56262],
[638.4798, 122.56262],[ 652.50616, 119.102554],
[652.50616, 119.102554],[ 666.3739, 116.87822],
[666.3739, 116.87822],[ 679.47644, 116.87822],
[679.47644, 116.87822],[ 695.8207, 116.87822],
[695.8207, 116.87822],[ 703.9951, 116.25368],
[703.9951, 116.25368],[ 713.08514, 114.554535],
[713.08514, 114.554535],[ 719.17285, 112.84549],
[719.17285, 112.84549],[ 724.0949, 110.882904],
[724.0949, 110.882904],[ 729.0887, 109.88368],
[729.0887, 109.88368],[ 736.0799, 105.88681]
]

cv2.drawContours(im, [points], 3, (0,255,0), 3)
cv2.imshow("",im)
cv2.waitKey(0)


我期望带有自由线的图像!其中线覆盖不与图像绑定(bind)。

最佳答案

您可以使用polylines

结果:
enter image description here

代码:

import cv2
import numpy as np

# create the background, with 3 color channels
im = np.zeros([800, 1216, 3],np.uint8)

# create a numpy array with coordinates, dtype= np.uint32
points = np.array([
[405.49313, 141.8587],[444.5172, 135.35468],
[444.5172, 135.35468],[ 509.44876, 128.50587],
[509.44876, 128.50587],[ 541.78784, 127.92772],
[541.78784, 127.92772],[ 561.9265, 129.86807],
[561.9265, 129.86807],[ 580.7606, 130.36917],
[580.7606, 130.36917],[ 605.0242, 127.64725],
[605.0242, 127.64725],[ 623.9638, 125.8712],
[623.9638, 125.8712],[ 638.4798, 122.56262],
[638.4798, 122.56262],[ 652.50616, 119.102554],
[652.50616, 119.102554],[ 666.3739, 116.87822],
[666.3739, 116.87822],[ 679.47644, 116.87822],
[679.47644, 116.87822],[ 695.8207, 116.87822],
[695.8207, 116.87822],[ 703.9951, 116.25368],
[703.9951, 116.25368],[ 713.08514, 114.554535],
[713.08514, 114.554535],[ 719.17285, 112.84549],
[719.17285, 112.84549],[ 724.0949, 110.882904],
[724.0949, 110.882904],[ 729.0887, 109.88368],
[729.0887, 109.88368],[ 736.0799, 105.88681]
], np.int32)
# reshape array
points = points.reshape((-1,1,2))
# draw a line between coordinates
im = cv2.polylines(im,[points],True,(0,0,255))
# show image
cv2.imshow("",im)
cv2.waitKey(0)
cv2.destroyAllWindows()

关于python - 如何使用drawcontours为给定坐标绘制徒手线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56326908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com