- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试绘制从 DXF 文件中提取的样条曲线的光栅表示。我使用 ezdxf 库从 DXF 文件中提取数据,并使用 Python Wand 库 (ImageMagick) 来绘制图像。 Wand 具有样条函数,但它绘制的内容并不总是与 DXF 文件中的曲线匹配。这并不奇怪,因为 Wand 样条函数没有节点或 DXF 样条曲线阶数的输入。下图显示了 DXF 形状的外观。 Wand 样条函数在一个示例中运行良好,但在另一个示例中则不然。
第一个是样条椭圆Oval Example .
第二个是书脊矩形 Rectangle Example .
这些形状的 DXF 文件中的数据点和结已被提取并在以下创建示例位图的示例代码中使用。即使不考虑结和度数,椭圆形也能很好地渲染 test_image_oval.bmp .
矩形的所有边和角都变形 test_image_rect.bmp .
控制点以红色绘制。包含但未使用结。
from wand.image import Image
from wand.color import Color
from wand.drawing import Drawing
############################################
point_list_oval = [ (5.0, 1.5, 0),
(5.0, 0.6715728753, 0),
(3.8807118745, 0.0, 0),
(2.5, 0.0, 0),
(1.1192881255, 0.0, 0),
(0.0, 0.6715728753, 0),
(0.0, 1.5, 0),
(0.0, 2.3284271247, 0),
(1.1192881255, 3.0, 0),
(2.5, 3.0, 0),
(3.8807118745, 3.0, 0),
(5.0, 2.3284271247, 0),
(5.0, 1.5, 0)]
knots_oval = [0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0]
############################################
point_list_rect = [(3.75, 0.0, 0),
(3.75, 0.0, 0),
(0.25, 0.0, 0),
(0.25, 0.0, 0),
(0.1125, 0.0, 0),
(0.0, 0.1125, 0),
(0.0, 0.25, 0),
(0.0, 0.25, 0),
(0.0, 5.75, 0),
(0.0, 5.75, 0),
(0.0, 5.8875, 0),
(0.1125, 6.0, 0),
(0.25, 6.0, 0),
(0.25, 6.0, 0),
(3.75, 6.0, 0),
(3.75, 6.0, 0),
(3.8875, 6.0, 0),
(4.0, 5.8875, 0),
(4.0, 5.75, 0),
(4.0, 5.75, 0),
(4.0, 0.25, 0),
(4.0, 0.25, 0),
(4.0, 0.1125, 0),
(3.8875, 0.0, 0),
(3.75, 0.0, 0)]
knots_rect = [0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 6.0, 6.0, 6.0, 7.0, 7.0, 7.0, 8.0, 8.0, 8.0, 8.0]
############################################
def draw_spline(img_width, img_height, DPI, point_list, filename):
POINT_SIZE = 1
STROKE_WIDTH = 0.5
img = Image(width=img_width, height=img_height, background=Color('white'))
# Convert the points to a 96dpi image space, remove the z axis
converstion_list = []
for point in point_list:
point = (int(round(point[0] * DPI)), int(round(point[1] * DPI)))
converstion_list.append(point)
point_list = converstion_list
# Draw the control points
with Drawing() as draw:
draw.stroke_width = STROKE_WIDTH
draw.stroke_color = Color('red')
draw.fill_color = Color('red')
print '---------------------'
print 'image points'
for point in point_list:
perim = (point[0] + POINT_SIZE, point[1])
draw.circle(point, perim)
print point
draw(img)
# draw the bezier path
with Drawing() as draw:
draw.stroke_width = STROKE_WIDTH
draw.stroke_color = Color('green')
draw.fill_color = Color('transparent')
draw.bezier(point_list)
draw(img)
img.save(filename=filename)
############################################
DPI = 96
draw_spline(577,385, DPI, point_list_oval,'test_image_oval.bmp')
draw_spline(577, 700, DPI, point_list_rect, 'test_image_rect.bmp')
有人知道如何使用 Wand 库生成样条曲线并考虑节点和度数以及数据点吗?
我还尝试使用 SciPy 库样条函数 (interpolate.splprep),但效果有限。这是解决方案的另一种可能性。遵循该路径意味着使用 SciPy 库对大量点进行插值,并使用 Wand 中的折线函数来逼近曲线。如果有人感兴趣,我也可以包含该示例代码,但我不想让线程过于困惑。
任何有关 Spline 和 Wand 的见解将不胜感激。
谢谢。
最佳答案
要理解的关键是贝塞尔曲线是样条曲线,但并非所有样条曲线都是贝塞尔曲线。因此,对于 DXF,只需绘制四坐标 block ,并使用最后使用的点作为下一次迭代的第一个点。
# draw the bezier path
with Drawing() as draw:
draw.stroke_width = STROKE_WIDTH
draw.stroke_color = Color('green')
draw.fill_color = Color('transparent')
chunk = [] # Prototype a temporary list.
for points in point_list: # Iterate over all points.
chunk.append(points) # Append to temporary list.
if len(chunk) == 4: # Ready to draw?
draw.bezier(chunk) # Draw spline segment.
del chunk[0:3] # Clear first three items, and reuse last point.
draw(img)
关于python - 使用 Wand 和 Python 生成样条曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49023851/
我想将 pdf 的第一页转换为图像。我的以下代码在我的本地环境中运行良好:Ubuntu 18。但是当我在 docker 环境中运行时,它失败并引发: wand.exceptions.WandRunti
我正在尝试运行一个脚本,该脚本将遍历特定文件夹并使用 Wand 为其在该文件夹中找到的每个 .pdf 文件创建一个 .png 文件。 from wand.image import Image impo
我正在尝试使用 python Wand 调整图像大小,保留纵横比并使用透明度填充剩余位置。例如,我想在保持纵横比的同时将一个大矩形缩小以适应 100x100 图像,但我希望返回一个 100x100 的
所以,我正在使用 Wand Python Library弄乱一些图像。 我只是希望它逐个像素地查看图像,对于特定颜色的每个像素,例如“4d4d4d”,将该像素颜色替换为其他颜色,例如“#00ff00”
我想打开一个 pdf 文件,只获取第一页并将其另存为图像。我用过 this solution它工作完美。它在我的本地环境中仍然有效,但最近在 Travis 中无法正常工作。 是的,这段代码来 self
我们使用Celery下的Python Wand来处理很多图片。在我们的一些服务器上,我们的处理有时会留下很多临时文件,例如: $ ls -lh/tmp/ -rw------- 1 ubuntu ubu
我正在编写一个 django/python 应用程序,我需要将用户上传的 PDF 文件转换为 JPEG(文件是扫描文件) 我正在尝试使用带有 ImageMagick 后端(在 OSX 上)和 我不断收
如果我执行以下操作 for root, dirs, files in os.walk(myDir): for myFile in files: with Image(filename=my
如何在 wand (python) 中并排堆叠两个图像?复合方法是可用的,但它将一个图像放在另一图像之上。我想要像 numpy.vstack 这样的东西。 最佳答案 您还可以使用 smush() 并在
我正在尝试使用Wand创建一个多尺寸的 ico,但我没有找到任何关于此的内容,只有正常的转换,到 ico...我找到了“序列”: https://wand.readthedocs.org/en/lat
我正在尝试在 Python 上的 Wand 中编写一个自动化脚本,通过一次一个字母地编写图像标题来构建文本动画的框架。 问题是,当我使用标题命令(此处的文档 http://docs.wand-py.o
我在 Tesseract OCR 中使用了下面的图片: 我处理图片的代码是: # HOCR with image[450:6200, 840:3550] as cropped: imgPage
您好,我正在尝试在图像上写文字。但是文字溢出来了。有什么方法可以将此类文本内容包裹起来以适合图像? from wand.image import Image from wand.drawing imp
Imagemagick是用于显示、转换和编辑光栅图像文件的开源软件套件。 Wand是 ctypes用于 Python 的基于 ImageMagick 的绑定(bind)。 我如何获得图像文件列表,这是
我有一张图片(例如:mask)和两个整数,代表最终图片的宽度和高度。根据 Wand 的文档 Open empty image : with Image(width=200, height=100) a
我正在构建一个应用程序,它使用棒调整系统中照片的大小并生成缩略图。我想生成移动的 gif 缩略图,它在下面的代码中工作。但是我不想获得巨大的缩略图文件大小。如果缩略图超过 5mb,我希望它生成 jpe
这是我的代码: class ToPng(APIView): def post(self, request, *args, **kwargs): revision = reque
我的小脚本有问题。我想使用 wand 来将 PDF 文件转换成 jpeg 文件,我想只保存一个特定的帧。 我的脚本做了两件事: 如果 PDF 文档只有一页:将其转换并保存为 jpeg 文件(有效) 如
我想在使用 dplyr 编写现有代码的同时使用 plyrmr 包,因此我想使用“magic.wand”函数。为简单起见,我使用“mtcars”数据集,它的路径是 HDFS(Hadoop 分布式文件系统
我有这段代码,以 pdf 文件作为参数并将其转换为 JPG。我的问题是,当 pdf 有多于一页时,创建像这样的图像:test-0.jpg、test-1.jpg 等。 with Img(filenam
我是一名优秀的程序员,十分优秀!