trouble passing image from c to matlab..
이전 댓글 표시
...
mxArray *mat1;
UINT8_T *dynamicData;
mwSize index;
unsigned long int elements;
elements = (ImgTempTp->width)*(ImgTempTp->height);
dynamicData = mxCalloc(elements, sizeof(UINT8_T));
for ( index = 0; index < elements; index++ ) {
dynamicData[index] = ImgTempTp->imageData[index];
}
mat1 = mxCreateNumericMatrix(0, 0, mxUINT8_CLASS, mxREAL);
mxSetData(mat1, dynamicData);
mxSetM(mat1, ImgTempTp->height);
mxSetN(mat1, ImgTempTp->width);
mlfShowimage(mat1);
.
.
ImgTempTp is an image created by opencv. the data type is unsigned char.
function [] = showimage(img)
figure,imshow(img);
input('Press Enter to continue...');
end
Some times the image appears properly but many times it gets mixed up in 2-3 manners i.e. it has 2-3 sections which contains parts of original image in tilted fashion
I have tried memcpy also. But i get the same error.. PLs help...
답변 (2개)
Kaustubha Govind
2011년 5월 11일
Is there a reason your are using a rather roundabout way to achieve this? Why not use something like:
...
mxArray *mat1;
UINT8_T *dynamicData;
mwSize index;
unsigned long int elements;
elements = (ImgTempTp->width)*(ImgTempTp->height);
mat1 = mxCreateNumericMatrix(ImgTempTp->height, ImgTempTp->width, mxUINT8_CLASS, mxREAL);
dynamicData = (UINT8_T *)mxGetData(mat1);
for ( index = 0; index < elements; index++ ) {
dynamicData[index] = ImgTempTp->imageData[index];
}
mlfShowimage(mat1);
.
.
Do you know if ImgTempTp->imageData contains the image in the right indexing order? It seems like the image is being read along the diagonal. Have you tried examining the contents of ImgTempTp->imageData and comparing them with the value 'img' that's passed into showimage?
댓글 수: 3
Vikash Anand
2011년 5월 11일
Vikash Anand
2011년 5월 11일
Kaustubha Govind
2011년 5월 11일
Could it be than opencv is somehow not storing the pixel values in the expected linear order?
카테고리
도움말 센터 및 File Exchange에서 OpenCV Support에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!