我想要可视化google的quickdraw数据,基本上有一个数据集(ndjson),其中每行包含一个绘图:
{
"key_id":"5891796615823360",
"word":"nose",
"countrycode":"AE",
"timestamp":"2017-03-01 20:41:36.70725 UTC",
"recognized":true,
"drawing":[[[129,128,129,129,130,130,131,132,132,133,133,133,133,...]]]
}我的问题是:我如何才能使绘图可视化?它说数组的格式是:
[
[ // First stroke
[x0, x1, x2, x3, ...],
[y0, y1, y2, y3, ...],
[t0, t1, t2, t3, ...]
],
[ // Second stroke
[x0, x1, x2, x3, ...],
[y0, y1, y2, y3, ...],
[t0, t1, t2, t3, ...]
],
... // Additional strokes
]但我仍然不知道如何将它可视化,我已经看到了一个答案,here,我也不知道python,什么是木星,还有其他方法吗?提前谢谢你
QuickDraw数据集github:https://github.com/googlecreativelab/quickdraw-dataset
发布于 2021-02-01 10:02:32
即使你不是很了解Python,你仍然可以使用这些数据:
在Python中绘制有很多方法(例如PIL ImageDraw、pygame、opencv等)。
将多段线描述为[[x1,y1],[x2,y2],etc.]非常直观。数据集的唯一问题是数据格式为[[x1,x2,etc.],[y1,y2,etc.]]
你可以很容易的合并x1,x2,...有了y1,y2,...使用zip()的数据
然后,您可以轻松地遍历每条多段线,并使用您选择的Python API对其进行渲染。
以下是使用PIL和cat quickdraw数据集的示例:
import json
from PIL import Image, ImageDraw
# read ndjson lines
lines = open('full_simplified_cat.ndjson','r').readlines()
# grab the first line, JSON parse it and fetch the 'drawing' array
raw_drawing = json.loads(lines[0])['drawing']
print('before',raw_drawing)
# zip x,y coordinates for each point in every polyline
polylines = (zip(polyline[0], polyline[1]) for polyline in raw_drawing)
# notice how the data is shuffled to (x1,y1),(x2,y2) order
print('after',polylines)
# make a new image
pil_img = Image.new("RGB", (240, 270), (255,255,255))
# get a drawing context
d = ImageDraw.Draw(pil_img)
# render each polyline
for polyline in polylines:
d.line(polyline,fill=(0, 0, 0),width=3)
# display image
pil_img.show()

更新:
您已链接到上面的QuickDraw数据集范围包括一个指向quickdraw python module的链接,该链接使快速绘制数据的可视化变得非常简单:
from quickdraw import QuickDrawData
qd = QuickDrawData()
anvil = qd.get_drawing("anvil")
anvil.image.show()上面的代码片段是来自https://github.com/martinohanlon/quickdraw_python/tree/master/examples的show_image.py示例
https://stackoverflow.com/questions/63375078
复制相似问题