opencv C ++ polar coordinate transformation

#include <opencv2 / Core / core.hpp> 
#include <opencv2 / HighGUI / highgui.hpp> 
#include <opencv2 / imgproc / imgproc.hpp> 
#include <the iostream> // Center: transform coordinates of the center pole
 // MINR : minimum distance transform of the center
 // mintheta: minimum distance
 // thetaStep: length converting step angle
 // Rstep: conversion step distance 
cv :: Mat polar (cv :: Mat I, cv :: Point2f center, cv: : size size, a float MINR = 0 , a float mintheta = 0 , a float thetaStep = 1.0 / . 4 , a float Rstep = 1.0 ) { 
    CV :: Mat RI

=cv::Mat::zeros(cv::Size(1,size.height),CV_32FC1);
    for(int i=0;i<size.height;++i)
        ri.at<float>(i,0)=minr+i*rStep;
    cv::Mat r=cv::repeat(ri,1,size.width);
    cv::Mat thetaj=cv::Mat::zeros(cv::Size(size.width,1),CV_32FC1);
    for(int i=0;i<size.width;++i)
        thetaj.at<float>(0,i)=mintheta+i*thetaStep;
    cv::Mat theta=cv::repeat(thetaj,size.height,1);
    cv::Mat x,y;
    cv::polarToCart(r,theta,x,y,true);
    x+=center.x;
    y+=center.y;
    cv::Mat dst =125*cv::Mat::ones(size,CV_8UC1);
    for(int i=0;i<size.height;++i){
        for(int j=0;j<size.width;++j){
            float xij=x.at<float>(i,j);
            float yij=y.at<float>(i,j);
            int nearestx=int(round(xij));
            int nearesty=int(round(yij));
            if((0<=nearestx&&nearestx<I.cols)&&(0<=nearesty&&nearesty<I.rows))
                dst.at<uchar>(i,j)=I.at<uchar>(nearesty,nearestx);
        }
    }
    return dst;
}


int main(){
    cv::Mat I=cv::imread("/home/nan/图片/openimage/circleWithText.jpg",cv::IMREAD_GRAYSCALE);
    if(!I.data) return- . 1 ;
     a float thetaStep = 1.0 / . 4 ;   // thetaStep = 0.25 representative of the ring, thetaStep = 0.5 Representative half ring, thetaStep = 1 1/4 Representative rings. 
    a float MINR = 55 ; 
    CV :: Size size ( int ( 360 / thetaStep), 50 );   // 50: height substantially annular text.
    // annular angular range (0,360), the ring width of the output image is (360 / thetaStep): 
    CV = :: Mat Polar DST (the I, CV :: Point2f ( 110 , 109 ), size, MINR);
     / / CV :: imshow ( "polar coordinate conversion 0:", DST); 
    CV :: Flip (DST, DST, 0 );   //The X-meansflipping around 0 Axis and positive value (for Example,. 1) means
     // Flipping around Y-Axis. Negative value (for Example, -1) Flipping means around both axes. 
    CV :: imshow ( " the I " , the I ); 
    CV :: imshow ( " nearest neighbor interpolation polar coordinate conversion: " , DST); 

    CV :: linearPolar (the I, DST, CV :: Point2f ( 110 , 109 ), 100 , CV :: INTER_LINEAR); 
    CV :: imshow ( " linear interpolation polar coordinate conversion: " , DST); 

    CV :: logPolar (the I, DST, CV :: Point2f ( 110 , 109 ), 40 , CV :: WARP_FILL_OUTLIERS); 
    CV :: imshow (" Logarithmic polar coordinate transformation: " , DST);
     // CV :: InterpolationFlags 
    CV :: waitKey ( 0 );
     return  0 ; 
}

Guess you like

Origin www.cnblogs.com/ligei/p/11529031.html