【问题标题】:error with python saying invalid syntax trying to create list of struct错误与 python 说无效的语法试图创建结构列表
【发布时间】:2018-06-11 11:42:53
【问题描述】:

在相机切除的关键帧中,我试图创建一个出现在帧中的点列表,然后尝试创建一个包含以下帧中对应点的列表,以继续跟踪视频中的点以找到它们之间的K矩阵。

我有以下类来存储每个帧的点,并为每个帧创建一个点列表并沿着所有帧跟踪它们。

class PointsCorrespondence:
    """
    Stores the point of a specific index.
    """

    # A point is represented as (coordinate X, coordinate Y)
    Point = (float, float)

    # A point with corresponding same point is represented as (coordinates, index of the corresponding point or -1 if there is no corresponding point).
    PointWithCorrespondence = (Point, int)

    # Contains the points represented as one list of notable points for each frame.
    _pointsPerFrame : [[PointWithCorrespondence]]

    def __init__(self, pointsPerFrame : [[PointWithCorrespondence]]):
        self._pointsPerFrame = pointsPerFrame

当我尝试运行此代码来存储其中的点时,出现以下错误:

Traceback(最近一次调用最后一次):文件“main.py”,第 4 行,在 导入点跟踪文件“/home/k/Desktop/CV/project/insertc/project12345/pointTracking.py”, 第 17 行

_pointsPerFrame : [[PointWithCorrespondence]]
                ^ SyntaxError: invalid syntax

其实我不知道为什么会出现这个错误,我尝试了很多方法来检查 python 语法样式。

我正在使用 python 3.4

【问题讨论】:

  • 你是想在那里定义types,还是values?这很令人困惑。您使用的是哪个版本的 Python?
  • 我在 ubuntu 14.04 上使用 python 3.4.3 默认版本
  • 这只是我将用来存储我的观点的变量的初始化
  • 嗯:1. 这是一个类属性,你实际上不需要“初始化”来设置一个实例属性;和 2. 你似乎混淆了将 values 分配给这些属性(例如,(float, float) 是一个双元组文字,内置 float 类作为两个元素)与指定 types,所以请澄清预期的行为。你的队友也在用 3.4.x 吗?

标签: python python-3.x opencv computer-vision camera-calibration


【解决方案1】:

变量注解在 Python 3.6 中是新的,参见例如what's newPEP-526;您需要升级才能使用此语法。请注意,您将 values 分配给其他两个类属性,而不是注释 types;这可能是无意的。

【讨论】:

    猜你喜欢
    • 2015-02-15
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 2019-12-09
    • 2018-08-01
    • 1970-01-01
    • 2017-01-21
    相关资源
    最近更新 更多