圆柱坐标系插图。线积分

来源:互联网 发布:xlsb文件怎么打开 mac 编辑:程序博客网 时间:2024/06/09 17:37

// shear.cpp : Defines the entry point for the console application.
//

#include <cv.h>
#include <highgui.h>

int casting(int x0, int r){        // x0   -r,r
    float bk = (float)r*(asin((float)x0/(float)r)) + 3.14 / 2.0 * (float)r;
    return (int)bk;
}


int casting1(int d, int r){
    float bk = (float)r*sin((float)d/(float)r - 3.14 / 2.0) + (float)r;
    return (int)bk;
}

// 圆内线积分可以求原图中横坐标
int casting2(float angle, float r, float widths, int x0){
    angle = 2 * 3.14 * (angle / 360);
    float x_fin,x_start;
    x_fin = r * cos(angle - widths / 3.14 / r * (3.14/2));
    x_start = r * cos(angle + widths / 3.14 / r * (3.14/2));
    
    if (angle + widths / 3.14 / r * (3.14/2)<=3.14){
        return r*asin((float)x0/r) - r*asin((float)x_start/r);
    }
    else if (angle - widths / 3.14 / r * (3.14/2)<=3.14){
        float befval =  r*asin((float)x_start/r) - r*asin(-1.0);
        //printf("/nbef=%f/n",befval);
        return r*asin((float)x0/r) - r*asin(-1.0) + befval;
    }
    else {
        return r*asin((float)x_fin/r) - r*asin((float)x0/r);
    }

}

int main()
{
    int a;
    int w = casting2(180,5,3.14*5,0);
    printf("%d",w);
    
    int theta;
    for (theta = 0;theta <=180;theta+=10) {
    IplImage* src = cvLoadImage("c://fruit.bmp");
    int r = src->width;
    IplImage* dst = cvCreateImage(cvSize(2*r, src->height),src->depth,src->nChannels);
    for (int i=0;i<dst->width;i++) for (int j=0;j<dst->height;j++) for (int z=0;z<dst->nChannels;z++)
        dst->imageData[j*dst->widthStep+i*dst->nChannels+z] = 255;

    for (int i= - (dst->width/2);i< dst->width/2 ;i++) {
        //int wth = casting(i ,dst->width);
        int wth = casting2(theta,r,src->width,i);
        printf("%d ",wth);
        for (int j=0;j<dst->height;j++) for (int z=0;z<dst->nChannels;z++){
            //if (wth<0) wth = -wth;
            if (wth<src->width&&wth>=0)     dst->imageData[j*dst->widthStep+(i+dst->width/2)*dst->nChannels+z] = src->imageData[j*src->widthStep+wth*src->nChannels+z];
        }
    }
    printf("theta:%d",theta);
    cvNamedWindow("ab");
    cvShowImage("ab",dst);
    cvWaitKey(0);
    }
    return 0;
}

原创粉丝点击