圆柱坐标系插图。线积分

// 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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值