简体   繁体   English

C ++-可以在OpenCV中使用Vec3b的一些解释

[英]C++ - Could use a little explanation of Vec3b in OpenCV

I ran into this 'Vec3b green(0,255,0), blue (255,0,0);' 我遇到了这个'Vec3b绿色(0,255,0),蓝色(255,0,0);' in some code I'm converting to another language. 在某些代码中,我正在转换为另一种语言。 I'm new to C++ OpenCV and was wondering where it is in the Documentation, I searched everywhere and couldn't find it. 我是C ++ OpenCV的新手,我想知道它在文档中的位置,我到处搜索并找不到它。 I also grepped the entire OpenCV directory and found this to be the closest to a definition of it 我还grep整个OpenCV目录,发现这是最接近它的定义

'typedef Vec3b RGB;' 'typedef Vec3b RGB;'

in the /home/w/Documents/opencv-master/modules/imgproc/test/test_cvtyuv.cpp file 在/home/w/Documents/opencv-master/modules/imgproc/test/test_cvtyuv.cpp文件中

I grepped for RGB and couldn't find a definition on that either though there was alot of output on it and I may have missed something. 我尝试了RGB,尽管有很多输出,但找不到关于它的定义,我可能错过了一些东西。 I'm writing a C wrapper for it is why I need to know, so far I have this to wrap the above 'Vec3b green(0,255,0)': 我正在写一个C包装程序,这就是为什么我需要知道,到目前为止,我已经用它包装了上面的'Vec3b green(0,255,0)':

 Vec3b cv_create_Vec3b(const char* color, int val1, int val2, int val3) {
     return new Vec3b color (val1, val2, val3);
 }

But gets this error: 但是得到这个错误:

 opencv_generated.cpp:8:22: error: expected ‘;’ before ‘color’
      return new Vec3b color (val1, val2, val3);
                  ^
opencv_generated.cpp:8:45: error: ‘color’ cannot be used as a function
     return new Vec3b color (val1, val2, val3);

I, first of all, could use help, to find out how to type "color" . 首先,我可以使用帮助来查找如何键入“ color”。 It just needs a variable that would be "green" or "blue" whatever is input when it ran(new to C++ kind of)..Second just if someone could point me to or tell me info on it or show me a declaration on it so I'd have enough info to write my wrapper I'd be grateful. 它只需要一个变量,无论运行时输入了什么(对于C ++来说都是新的),它都将是“绿色”或“蓝色”。其次,有人可以指向我或告诉我有关其的信息或向我显示声明这样,我将有足够的信息来编写包装器,我将不胜感激。

Thank you ^ 谢谢^

Vec3b is a type (looks like a color value to me) and "green" and "blue" are variable names. Vec3b是一种类型(在我看来就像一个颜色值),“ green”和“ blue”是变量名。 You can't store variable names in strings (obviously) and hence you can't have a function which generates these values. 您不能(显然)将变量名存储在字符串中,因此您不能具有生成这些值的函数。 Also, your function is syntactically wrong. 另外,您的函数在语法上是错误的。 While i don't understand how you would write ac wrapper to a c++ project (if part of it is in c++, you need a c++ compiler, so what's the point?), I'd definitely recommend you to learn c++ before attempting anything with it. 虽然我不明白如何将ac包装器写入c ++项目(如果其中的一部分在c ++中,则需要使用c ++编译器,这有什么用?),我绝对建议您在尝试任何操作之前先学习c ++。用它。 The syntactic possibilities are too far and wide to just learn by yourself while reading code. 语法的可能性太广泛了,以至于在阅读代码时只能自己学习。

EDIT: maybe try something like this? 编辑:也许尝试这样的事情?

Vec3b Green() {
    Vec3b result(0, 255, 0);
    return result;
}

I found how to do it n another SO post. 我在另一篇SO帖子中找到了如何做。 pls see comments 请看评论

here https://stackoverflow.com/questions/22311634/c-help-writing-function-parameters-for-c-wrappers-for-c 在这里https://stackoverflow.com/questions/22311634/c-help-writing-function-parameters-for-c-wrappers-for-c

Vec3b* cv_create_Vec3b(int val1, int val2, int val3) {
   return new Vec3b (val1, val2, val3);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM