synthesis Rotation Repeatability with SIFT and SURF

asked 2014-08-23 09:55:29 -0500

AMH gravatar image

Hi

i rotate images with below code which i find on Stackoverflow website

                 int theta = 10*(counter);
                 counter++ ; 
                 Mat src,frame, frameRotated;
                 src = img_1c;


                 int diagonal = (int)sqrt((double)    (src.cols*src.cols+src.rows*src.rows));
                 int newWidth = diagonal;
                 int newHeight =diagonal;

                 int offsetX = (newWidth - src.cols) / 2;
                 int offsetY = (newHeight - src.rows) / 2;
                 Mat targetMat(newWidth, newHeight, src.type());
                 Point2f src_center(targetMat.cols/2.0F, targetMat.rows/2.0F);

             src.copyTo(frame);
                 double radians = theta * M_PI / 180.0;
                 double sin = abs(std::sin(radians));
                 double cos = abs(std::cos(radians));

             frame.copyTo(targetMat.rowRange(offsetY, offsetY + frame.rows).colRange(offsetX, offsetX + frame.cols));
                 Mat rot_mat = getRotationMatrix2D(src_center, theta, 1.0);
                 warpAffine(targetMat, frameRotated, rot_mat, targetMat.size());
                 Rect bound_Rect(frame.cols,frame.rows,0,0);

             int x1 = offsetX;
             int x2 = offsetX+frame.cols;
                 int x3 = offsetX;
                 int x4 = offsetX+frame.cols;

             int y1 = offsetY;
                 int y2 = offsetY;
                 int y3 = offsetY+frame.rows;
                 int y4 = offsetY+frame.rows;

                 Mat co_Ordinate = (Mat_<double>(3,4) << x1, x2, x3, x4,
                             y1, y2, y3, y4,
                             1,  1,  1,  1 );
            Mat RotCo_Ordinate = rot_mat * co_Ordinate;

                     for(int i=0;i<4;i++){
                if(RotCo_Ordinate.at<double>(0,i)<bound_Rect.x)
                 bound_Rect.x=(int)RotCo_Ordinate.at<double>(0,i); //access smallest 
                     if(RotCo_Ordinate.at<double>(1,i)<bound_Rect.y)
                  bound_Rect.y=RotCo_Ordinate.at<double>(1,i); //access smallest y
                         }

                 for(int i=0;i<4;i++){
                 if(RotCo_Ordinate.at<double>(0,i)>bound_Rect.width)
                 bound_Rect.width=(int)RotCo_Ordinate.at<double>(0,i); //access largest x
                 if(RotCo_Ordinate.at<double>(1,i)>bound_Rect.height)
                bound_Rect.height=RotCo_Ordinate.at<double>(1,i); //access largest y
                         }

             bound_Rect.width=bound_Rect.width-bound_Rect.x;
             bound_Rect.height=bound_Rect.height-bound_Rect.y;

             Mat cropedResult;
             Mat ROI = frameRotated(bound_Rect);
             ROI.copyTo(cropedResult);

and compute homography with below code which i have written:

 int im1rows = img_1.rows;
                 int im1cols = img_1.cols;
                 cv::Size s1 = img_1.size();
                 im1rows = s1.height;
                 im1cols = s1.width;
                 float centerX1 ;
                 float centerY1 ;
                 int im2rows = img_2.rows;
                 int im2cols = img_2.cols;
                 cv::Size s2 = img_2.size();
                 im2rows = s2.height;
                 im2cols = s2.width ; 
                 float centerX2;
                 float centerY2;
                 if(theta==90)
                 {
                     centerX1=0 ; 
                     centerX2=im2rows;
                     centerY1=0;
                     centerY1=im2cols;
                 }
                 else if(theta==270)
                 {
                     centerX1=0 ; 
                     centerY1=0;
                     centerX2=im2rows;
                     centerY2=im2cols;
                 }

                 else
                 {
                     centerX1 = im1cols/2.0f;
                     centerY1 = im1rows/2.0f;
                     centerX2 = im2cols/2.0f;
                     centerY2 = im2rows/2.0f;
                 }


                 h12.create(3, 3, CV_32FC1);
                 (h12.row(0)).col(0)= cos ; 
                 (h12.row(0)).col(1)=-sin ; 
                 (h12.row(0)).col(2)=centerX2-centerX1 ; 
                 (h12.row(1)).col(0)=sin ;
                 (h12.row(1)).col(1)=cos ;
                 (h12.row(1)).col(2)=centerY2-centerY1;
                 (h12.row(2)).col(0)=0;
                 (h12.row(2)).col(1)=0;
                 (h12.row(2)).col(2)=1;

you can see that i made condition for 90 and 270 degrees since correspondence point was 0 when i evaluated rotated images with reference image with :

cv::evaluateFeatureDetector(img_1c, img_2c, h12, &key_points_1, &key_points_2, repeatability, corrCounter);

it's also happennig for 80 110 280 and 260 degrees .

i don't know if i compute homographies incorrectly or the rotation procedure ... (more)

edit retag flag offensive close merge delete