鸭梨鸭梨 2017-02-28 02:03 采纳率: 0%
浏览 1024
已采纳

C++ opencv的像素访问问题

我想问的是mat的ptr函数只能按行访问数据元素吗
/* .ptr with [] /
for ( int i=0; i {
uchar *data = image.ptr( i );
for ( int j=0; j<cols; j++ )
{
data[j] = 0;
/

if color one:
data[j*3 + 0] = 0;
data[j*3 + 1] = 0;
data[j*3 + 2] = 0;
*/
}
}

/* .ptr with pointer */
for ( int i=0; i {
uchar *data = image.ptr( i );
for ( int j=0; j<cols*image; j++ )
{
*data++ = 0;
}
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-02-28 02:57
    关注
     可以按列
    for ( int j=0; j<行数; j++ )
    *(data+(j * 每列大小) + 第几列)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?