0
私はこのコードを試みましたが、要素に正しくアクセスしていませんでした。CvCreateMatND直接アクセス
int size[] = { 5, 5, 5 };
CvMatND* matA = cvCreateMatND(3, size, CV_32F);
cvSetZero(matA);
printf("test: %d \n",cvGetReal3D(matA, 1, 1, 1));
cvSetReal3D(matA, 1, 1, 1, (cvGetReal3D(matA, 1, 1, 1)+1));
int test = cvGetReal3D(matA, 1, 1, 1);
printf("test: %d \n",test);
char cont = 1;
for (int dim_index = 0; dim_index < matA->dims; dim_index++)
{
printf("There are %d elements on dim %d\n", matA->dim[dim_index].size, dim_index);
for (int elem = 0; elem < matA->dim[dim_index].size; elem++)
{
printf("On element [%d] of dim %d, wrote: %d\n", elem, dim_index, matA->data.ptr[matA->dim[dim_index].size * dim_index + elem]);
}
}
出力:
test: 0
test: 1
There are 5 elements on dim 0
On element [0] of dim 0, wrote: 0
On element [1] of dim 0, wrote: 0
On element [2] of dim 0, wrote: 0
On element [3] of dim 0, wrote: 0
On element [4] of dim 0, wrote: 0
There are 5 elements on dim 1
On element [0] of dim 1, wrote: 0
On element [1] of dim 1, wrote: 0
On element [2] of dim 1, wrote: 0
On element [3] of dim 1, wrote: 0
On element [4] of dim 1, wrote: 0
There are 5 elements on dim 2
On element [0] of dim 2, wrote: 0
On element [1] of dim 2, wrote: 0
On element [2] of dim 2, wrote: 0
On element [3] of dim 2, wrote: 0
On element [4] of dim 2, wrote: 0
ありがとう!
あなたは結果として何を期待していますか? –
よく、私は1がdim [1]の要素[1]で返されると期待しています。これは、cvSetReal3D – Sharpie