在 HTML 中,我创建了一个具有唯一 ID 的“div”。在这个“div”中,我有更多的“div”,其中每个都包含一个字符串。例如:
<div id="name">
<div>A</div>
<div>B</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想要做的是在 id="name" 的“div”中找到包含字符串的“div”的索引,比如“A”。
我认为选择器 ":contains" 应该与 .index() 结合使用,但我无法弄清楚正确的语法。这是我尝试过的:
var index = $("#name"):contains(A).index("div");
Run Code Online (Sandbox Code Playgroud) 出于成像目的,我将Mat创建为
Mat_<Vec3f> I
Run Code Online (Sandbox Code Playgroud)
如果这是Vec3b Mat,那么我知道如何使用.data方法访问其元素。
I.data[j*I.step + i*3 + x], where x={0,1,2}, j is row and i is column
Run Code Online (Sandbox Code Playgroud)
我尝试对Vec3f进行相同操作,但以下所有内容均无效(引发错误):
I.data[j*I.step + i*12 + x], where x={0,4,8}
I.data[j*I.step[0] + i*I.step[1]*3 + x], where x={0,4,8}
I.data[j*I.step[0] + i*I.step[1]*3 + x], where x={0,I.step[1],I.step[1]*2}
Run Code Online (Sandbox Code Playgroud)
正确的方法是什么?我选择使用.data以获得更高的执行速度(与.at和.ptr相比)。