2013-05-16 6 views
2

SURF를 사용하여 장면에서 참조 이미지를 찾을 때 장면에서 찾은 객체를 잘라내어 warpPerspective와 역상을 사용하여 다시 "똑바로"표시하고 싶습니다. 호모 그래피 매트릭스. 내가 현장에서 발견 된 개체를 자르고 싶습니다 지금
enter image description here

:

의미의 내가이 SURF 결과가 있다고 가정 해 보자
enter image description here

을하고 "똑바로"단지 역전 된 호모 그래피 행렬을 사용하여 warpPerspective로 이미지를 자릅니다. 내가 목표로 한 결과는 대략 객체 만 포함하는 이미지와 원본 장면의 일부 왜곡 된 부분을 가져올 수 있다는 것입니다 (자르기는 객체 자체만으로는 100 %가 아닙니다).

발견 된 객체를 자르고, 호모 그래피 행렬을 찾고 그것을 뒤집는 것은 충분히 간단합니다. 문제는 warpPerspective의 결과를 이해할 수없는 것입니다. 결과 이미지가 자른 이미지의 작은 부분 만 포함하고 매우 큰 크기 인 것처럼 보입니다.
warpPerspective를 연구하면서 결과 이미지가 프로세스의 특성으로 인해 매우 커지는 것을 발견했지만 제대로 수행 할 수없는 방법으로 머리를 감싸고있는 것처럼 보일 수 없습니다. 나는 그 과정을 충분히 이해하지 못하는 것처럼 보입니다. 워프가 원래 이미지 (잘리지 않은 이미지)와 "똑 바르게 된"이미지를 자르려면 필요합니까?

어떤 조언이 필요합니까?OpenCV 2.4.3 - 자른 이미지의 동음 이음새가 뒤틀린 warpPerspective

+0

안녕하세요 u는 어떤 해결책을 찾았나요? – user1140237

+0

불행히도 다른 프로젝트를 처리하기 위해이 프로젝트를 남겨 두어야했지만 확실히 돌아갈 것입니다. 해결책을 찾아내는 경우, 결과를 게시 할 수 있다면 좋을 것입니다! –

+0

m 서핑 & 선별기를 사용하여 라이브러리를 구축 할 수 있지만 안드로이드 용으로 구현해야하는 문제가 있습니다 .. 그래서 tht에서 작업 중입니다 ... – user1140237

답변

1

시도해보십시오.

개체의 연결되지 않은 윤곽선 (예 : 상자 윤곽선의 바깥 쪽 모서리 점)이있는 경우 역상 동조 (inverse homography)로 변형 할 수 있고 해당 호모 그래피를 조정하여 그 변환 결과를 왼쪽 상단 영역에 배치 할 수 있습니다. 이미지. 그 객체 포인트에 만곡한다

  1. 컴퓨팅은 (역 호모 그래피 입력으로 윤곽 점 사용)

    cv::Rect computeWarpedContourRegion(const std::vector<cv::Point> & points, const cv::Mat & homography) 
    { 
        std::vector<cv::Point2f> transformed_points(points.size()); 
    
        for(unsigned int i=0; i<points.size(); ++i) 
        { 
         // warp the points 
         transformed_points[i].x = points[i].x * homography.at<double>(0,0) + points[i].y * homography.at<double>(0,1) + homography.at<double>(0,2) ; 
         transformed_points[i].y = points[i].x * homography.at<double>(1,0) + points[i].y * homography.at<double>(1,1) + homography.at<double>(1,2) ; 
        } 
    
        // dehomogenization necessary? 
        if(homography.rows == 3) 
        { 
         float homog_comp; 
         for(unsigned int i=0; i<transformed_points.size(); ++i) 
         { 
          homog_comp = points[i].x * homography.at<double>(2,0) + points[i].y * homography.at<double>(2,1) + homography.at<double>(2,2) ; 
          transformed_points[i].x /= homog_comp; 
          transformed_points[i].y /= homog_comp; 
         } 
        } 
    
        // now find the bounding box for these points: 
        cv::Rect boundingBox = cv::boundingRect(transformed_points); 
        return boundingBox; 
    } 
    
  2. 수정하여 역 호모 그래피 (입력으로 computeWarpedContourRegion 및 inverseHomography의 결과)

    cv::Mat adjustHomography(const cv::Rect & transformedRegion, const cv::Mat & homography) 
    { 
        if(homography.rows == 2) throw("homography adjustement for affine matrix not implemented yet"); 
    
        // unit matrix 
        cv::Mat correctionHomography = cv::Mat::eye(3,3,CV_64F); 
        // correction translation 
        correctionHomography.at<double>(0,2) = -transformedRegion.x; 
        correctionHomography.at<double>(1,2) = -transformedRegion.y; 
    
    
        return correctionHomography * homography; 
    } 
    
  3. 당신은 전화 무언가

  4. 같은 이 = 도움

cv::warpPerspective(objectWithBackground, output, adjustedInverseHomography, sizeOfComputeWarpedContourRegionResult);

희망)