2013-10-22 3 views
0

계속해서 컴퓨터 비전 도구를 사용하여 N 카메라의 패치에 대한 설명자를 계산합니다. 문제 나 기술자의 계산은 OpenCV의 펑션은 vecKeypointscv::KeyPointsmatDescriptors의 벡터이다std :: vector of cv :: Mat

descriptor.compute(image, vecKeypoints, matDescriptors); 

이다 할 때이다 OpenCV의의 의사에 따라이 채워 도착 cv::Mat 인 계산 된 디스크립터

저는 N 대의 카메라를 가지고 있으므로 카메라 당 여러 개의 디스크립터를 계산하므로 N 대의 카메라마다 K 개의 디스크립터를 저장하고 있습니다. 그러므로 나는 새로운 matDescriptors 계산 및 벡터 descriptors으로 밀어 각 반복에서 디스크립터의 벡터 (즉 매트릭스)

std::vector<cv::Mat> descriptors; 

을 만들었다. 내가 사본 vector.push_back(arg)을 수행 할 때 제가 보는 문제는 데이터가 matDescriptors의 각 매장입니다 주소가 설명 내가 아는 한

벡터의 모든 요소에 대해 동일이다 arg의 벡터가 만들어지고 벡터에 저장되면, 왜 같은 주소를 갖는 것입니까? &(descriptors[0].data)&(descriptors[1].data)과 달라야합니까?

는 Heres는 코드

std::vector<Pixel> patchPos; 
std::vector<Pixel> disparityPatches; 

//cv::Ptr<cv::DescriptorExtractor> descriptor = cv::DescriptorExtractor::create("ORB"); 
cv::ORB descriptor(0, 1.2f, 8, 0); 
std::vector<cv::Mat> camsDescriptors; 
std::vector<cv::Mat> refsDescriptors; 

uint iPatchV = 0; 
uint iPatchH = 0; 

// FOR EACH BLOCK OF PATCHES (there are 'blockSize' patches in one block) 
for (uint iBlock = 0; iBlock < nBlocks; iBlock++) 
{ 
    // FOR EACH PATCH IN THE BLOCK 
    for(uint iPatch = iBlock*blockSize; iPatch < (iBlock*blockSize)+blockSize; iPatch++) 
    { 
     // GET THE POSITION OF THE upper-left CORNER(row, col) AND 
     // STORE THE COORDINATES OF THE PIXELS INSIDE THE PATCH 
     for (uint pRow = (iPatch*patchStep)/camRef->getWidth(), pdRow = 0; pRow < iPatchV+patchSize; pRow++, pdRow++) 
     { 
      for (uint pCol = (iPatch*patchStep)%camRef->getWidth(), pdCol = 0; pCol < iPatchH+patchSize; pCol++, pdCol++) 
      { 
       patchPos.push_back(Pixel(pCol, pRow)); 
      } 
     } 

     // KEYPOINT TO GET THE DESCRIPTOR OF THE CURRENT PATCH IN THE REFERENCE CAMERA 
     std::vector<cv::KeyPoint> refPatchKeyPoint; 
     //   patchCenter*patchSize+patchCenter IS the index of the center pixel after 'linearizing' the patch 
     refPatchKeyPoint.push_back(cv::KeyPoint(patchPos[patchCenter*patchSize+patchCenter].getX(), 
               patchPos[patchCenter*patchSize+patchCenter].getY(), patchSize)); 

     // COMPUTE THE DESCRIPTOR OF THE PREVIOUS KEYPOINT 
     cv::Mat d; 
     descriptor.compute(Image(camRef->getHeight(), camRef->getWidth(), CV_8U, (uchar*)camRef->getData()), 
          refPatchKeyPoint, d); 
     refsDescriptors.push_back(d); // This is OK, address X has data of 'd' 

     //FOR EVERY OTHER CAMERA 
     for (uint iCam = 0; iCam < nTotalCams-1; iCam++) 
     { 
      //FOR EVERY DISPARITY LEVEL 
      for (uint iDispLvl = 0; iDispLvl < disparityLevels; iDispLvl++) 
      { 
       ... 
       ... 

       //COMPUTE THE DISPARITY FOR EACH OF THE PIXEL COORDINATES IN THE PATCH 
       for (uint iPatchPos = 0; iPatchPos < patchPos.size(); iPatchPos++) 
       { 
        disparityPatches.push_back(Pixel(patchPos[iPatchPos].getX()+dispNodeX, patchPos[iPatchPos].getY()+dispNodeY)); 
       } 
      } 

      // KEYPOINTS TO GET THE DESCRIPTORS OF THE 50.DISPAIRED-PATCHES IN CURRENT CAMERA 
      ... 
      ... 
      descriptor.compute(Image(camList[iCam]->getHeight(), camList[iCam]->getWidth(), CV_8U, (uchar*)camList[iCam]->getData()), 
           camPatchKeyPoints, d); 
      // First time this executes is OK, address is different from the previous 'd' 
      // Second time, the address is the same as the previously pushed 'd' 
      camsDescriptors.push_back(d); 

      disparityPatches.clear(); 
      camPatchKeyPoints.clear(); 
     } 
    } 
} 

답변

2

매트의 일반적인 도면 화소 스마트 포인터의 일종이기 때문에, B는 A와 B의 화소를 공유하는 = 매트. 당신이 '딥 카피'를 필요로하는 경우와 push_back 비슷한 상황()

는 함수 이력서 :: 매트 :: 릴리스() 전에 호출 할 수 있는지 확인하십시오, 모든 루프에서 매트 : 클론()

관련 문제