使用字符串定义Numpy数组切片(Using a string to define Numpy array slice)
我的图像数组的X倍Y形状为2048x2088。 x轴具有两个20个像素区域,一个在开始处,一个在末端,用于校准主图像区域。 要访问这些区域,我可以像这样切片数组:
prescan_area = img[:, :20] data_area = img[:, 20:2068] overscan_area = img[:, 2068:]
我的问题是如何在配置文件中定义这些区域,以便将此切片推广到其他可能具有不同预扫描和过扫描区域的摄像机,因此需要不同的切片。
理想情况下,类似下面的字符串将允许在相机特定配置文件中的简单表示,但我不知道如何将这些字符串转换为数组切片。
prescan_area_def = "[:, :20]" image_area_def = "[:, 20:2068]" overscan_area_def = "[:, 2068:]"
也许有一些明显的东西让我失踪?
谢谢!
I have an image array that has an X times Y shape of 2048x2088. The x-axis has two 20 pixel regions, one at the start and one at the end, which are used to calibrate the main image area. To access these regions I can slice the array like so:
prescan_area = img[:, :20] data_area = img[:, 20:2068] overscan_area = img[:, 2068:]
My question is how to define these areas in a configuration file in order the generalise this slice for other cameras which may have different prescan and overscan areas and therefore require a different slice.
Ideally, something like the strings below would allow a simple representation in the camera specific configuration file, but I am not sure how to translate these strings into array slices.
prescan_area_def = "[:, :20]" image_area_def = "[:, 20:2068]" overscan_area_def = "[:, 2068:]"
Maybe there is something obvious that I am missing?
Thanks!
原文:https://stackoverflow.com/questions/43089907
最满意答案
首先,类名不能以整数开头。 所以重命名它们:
class A { public: int stuff; private: class B { public: int stuffer; private: int x; }; };
其次,由于嵌套类
B
在私有部分中,因此您无法从类A
的范围之外访问它。B
仅可由A
访问。 声明类型B
的对象的语法是B bObj;
在A
的范围内。现在你应该先尝试自己,然后再提出更多问题!
至于你的编辑(增加的问题):它没有编译, 因为当编译器看到
B temp
,它还没有看到B
的定义,这就是为什么它说B
没有被声明!修复非常简单。 在使用它之前声明
B
,如下所示:class A { private: class B { public: int stuffer; private: int x; }; public: int stuff; void helper(B temp, int d); }; //<--- this is also fixed. your code has 'colon', instead semi-colon!
同时阅读课程结束时的评论!
First of all, class name cannot start with integer. So renaming them:
class A { public: int stuff; private: class B { public: int stuffer; private: int x; }; };
Second, since the nested class
B
is in the private section, so you cannot access it from outside the scope of classA
.B
is accessible toA
only. And the syntax of declaring an object of typeB
would beB bObj;
in the scope ofA
.Now you should try yourself first, before asking futher questions!
As for your edit (the added question): it's not compiling because by the time the compiler sees
B temp
, it has not yet seen the definition ofB
, that is why it saysB
is not declared!The fix is very simple. Declare
B
before it's used, something like this:class A { private: class B { public: int stuffer; private: int x; }; public: int stuff; void helper(B temp, int d); }; //<--- this is also fixed. your code has 'colon', instead semi-colon!
Also read the comment at the end of the class!
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
:用于“初始化”类的成员(此方法也称为成员初始化列表) 使用:和函数体{}之间存在重大差异 initiallizer list :初始化类的成员,而构造函数body {}将值赋给类的成员。 差异可能看起来不是很大,但它实际上是初始化const数据类型和reference数据类型成员的唯一方法(只能在声明期间初始化) 所以当你这样做 class Test { const int i; const string str; public: Test(int x, string y):i{x},str{y}; } ...
-
从语法上讲,不,除非你想编写一个函数或宏来执行它。 你可以,但如果你问我,只需使用访问器。 此外,您不希望在堆上分配大多数对象。 只需将它们声明为type foo; 或者type foo = type()并让它们在堆栈中。 除非有特别合理的理由,否则不应该使用动态分配将事物放在堆上,因为动态分配的开销很大。 Syntactically, no, not unless you want to write a function or macro to do it. You could, but if you a ...
-
没有优先选择的问题 ClassExample classExample2(); 和 ClassExample classExample3(void); 声明一个返回ClassExample对象的函数 There's no question of preferred option ClassExample classExample2(); and ClassExample classExample3(void); declares a function returning ClassExample objec ...
-
Kernlab中的类权重语法?(Class Weight Syntax in Kernlab?)[2022-04-29]
你的语法还可以,但是非工作级平衡的问题在机器学习中很常见; 在某种程度上,从较大的类中删除一些对象是唯一可以保证工作的方法,但它仍然可能是错误增加的来源,并且必须小心谨慎地以智能方式进行(在SVM中潜在的支持向量)应该有优先权 - 当然现在有一个问题如何找到它们。 您也可以尝试通过简单的长度比来增加重量,比方说十倍,并检查它是否有助于甚至一点点或幸运地反过来超过另一侧的不平衡。 Your syntax is ok, but the problem of not-working-class-balance i ... -
首先,类名不能以整数开头。 所以重命名它们: class A { public: int stuff; private: class B { public: int stuffer; private: int x; }; }; 其次,由于嵌套类B在私有部分中,因此您无法从类A的范围之外访问它。 B仅可由A访问。 声明类型B的对象的语法是B ...
-
Objective-C中没有static方法 - 你需要一个类方法。 替换-在声明前面加上+ ,如下所示: +(NSInteger) compare:(UniqueWord *self)a with:(UniqueWord *self)b; 类方法类似于C ++静态成员函数,但由于方法调度是在Objective-C中更动态地实现的,因此可以在派生类中为它们提供覆盖。 以上将编译。 但是,对于Objective-C来说,这不是惯用的,因为Cocoa使用NSComparisonResult而不是NSInteg ...
-
C ++类文件(C++ Class Files)[2022-02-22]
使用头文件的一个简单示例(在单独的.cpp文件中实现)看起来像这样: 你的main.cpp文件: #include "OtherClass.h" int main() { OtherClass otherClass; //use otherClass here... } 接下来,您的OtherClass.h文件: class OtherClass { public: OtherClass(); int someFunction(int parameters); }; ... -
C ++应该使用哪个类?(Which class should be used by C++?)[2022-05-14]
你的代码错了。 您已经定义了Class_A两次,并且定义不匹配。 这是不允许的 。 [C++11: 3.2/3] : 每个程序应该只包含该程序中使用的每个非内联函数或变量的一个定义; 无需诊断。 该定义可以在程序中明确显示,可以在标准或用户定义的库中找到,或者(在适当的时候)隐式定义(见12.1,12.4和12.8)。 内联函数应在每个使用它的翻译单元中定义。 [C++11: 3.2/5] : 类类型 (第9条),枚举类型(7.2),带内部链接的内联函数(7.1.2),类模板(第14条) 可以有多个定义 , ...