出于成像目的,我将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相比)。
只是先尝试使用前门;)
Vec3f & pixel = I.at<Vec3f>(j,i); // row, col world
Run Code Online (Sandbox Code Playgroud)
如果您确实需要一个指针,请至少使用:
Vec3f *pv = I.ptr<Vec3f>(j); // ptr to row j
pv[3][2] = 17; // 4th pixel, red channel
Run Code Online (Sandbox Code Playgroud)
换句话说,尽可能避免访问原始的uchar *数据
| 归档时间: |
|
| 查看次数: |
3795 次 |
| 最近记录: |