作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在图像上,我正在尝试为 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)
最佳答案
您可以使用polylines
结果:
代码:
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/
是否有功能或其他方法可以在Shiny中使用鼠标启用徒手绘制(即绘制随机形状/尺寸)? 具体来说,我希望能够通过以各种(但非均匀)方式进行标记来与renderPlot中的图进行“交互”。 -换句话说,我
我是一名优秀的程序员,十分优秀!