这份任务书是什么意思?

2024-10-06 12:07:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了一个Python脚本:

fea_det = cv2.xfeatures2d.SIFT_create()
des_ext = cv2.xfeatures2d.SIFT_create()

des_list = []

for image_path in image_paths:
    im = cv2.imread(image_path)
    kpts = fea_det.detect(im)
    kpts, des = des_ext.compute(im, kpts)
    des_list.append((image_path, des))

我的问题与不同变量和参数的含义无关,而与我们如何理解这一说法有关:

kpts, des = des_ext.compute(im, kpts)

kptsdes中会出现什么?它们的数据类型是什么?你知道吗


Tags: pathimage脚本createcv2extlistdet
2条回答

Comma separated identifiers on LHS of assignment statement performs iterable unpacking on result of RHS。报价文件:

If the target list is a comma-separated list of targets: The object must be an iterable with the same number of items as there are targets in the target list, and the items are assigned, from left to right, to the corresponding targets.

它们的数据类型是什么?

我不知道也不在乎。 执行赋值时与Python相同。它可能会关心你是否要求这些对象以后做些什么。你知道吗

Python有一种称为解包的机制。这在其他语言中称为解构赋值。你知道吗

它是这样的:当表达式的计算结果是iterable对象(例如listtuple)时,可以在赋值时将内部值分散到单独的变量:

def get_2_tuple():
    return ('foo', 'bar')

values = get_2_tuple() # no unpacking
foo, bar = values # unpacking!

foo, bar = get_2_tuple() # same-line unpacking

解包的行为可能是raiseException:函数get_2_tuple()必须返回一个iterable,其中正好有两个值才能工作。你知道吗

相关问题 更多 >