두 라이브러리를 사용하다보니 서로 변환할 일이 생겼다.. 그래서.. 구글 사마에게 물어보니 아래와 같은 답을 보여 주었다..

ARUint8 *dataPtr;
IplImage *image_opencv, *gray_opencv;

//ARToolkit→OpenCV
image_opencv = cvCreateImage(cvSize(arImXsize, arImYsize), IPL_DEPTH_8U, 4);
memcpy(image_opencv->imageData, dataPtr, image_opencv->imageSize);

//何らかの処理
gray_opencv = cvCreateImage(cvSize(arImXsize, arImYsize), IPL_DEPTH_8U, 1);
cvCvtColor(image_opencv, gray_opencv, CV_BGRA2GRAY);
cvAdaptiveThreshold(gray_opencv, gray_opencv, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, 11, 10);
cvCvtColor(gray_opencv, image_opencv, CV_GRAY2BGRA);

//OpenCV→ARToolkit
dataPtr = (ARUint8*)(image_opencv->imageData);




void ARtoIpl(IplImage* ipl, ARUint8* arimg,int flag){

int width = ipl->width; //ARのImageも同じ幅とする
int height = ipl->height; //ARのImageも同じ高さとする
int ARWidthStep = width * 4;

for(int j = 0; j < height; j++)
{
 for(int i = 0; i < width; i++)
{
  t0 = ipl->widthStep * j + i * ipl->nChannels;
  t1 = ARWidthStep * j + i * 4;
  
  for(int c = 0; c <>nChannels; c++)
{
   if(flag == -1) arimg[t1 + c] = ipl->imageData[t0 + c];
   else ipl->imageData[t0 + c] = arimg[t1 + c];
  }
 }
}




+ Recent posts