• 实验3.1


    #include <bits/stdc++.h>
    #include "opencv2/core.hpp"
    #include "opencv2/imgproc.hpp"
    #include "opencv2/video.hpp"
    #include "opencv2/objdetect.hpp"
    #include "opencv2/imgcodecs.hpp"
    #include "opencv2/highgui.hpp"
    #include "opencv2/ml.hpp"
    #define inf 2333333333333333
    #define N 1000010
    #define p(a) putchar(a)
    #define For(i,a,b) for(int i=a;i<=b;++i)
    typedef unsigned char uchar;
    //by war
    //2020.10.4
    using namespace std;
    using namespace cv;
    int T;
    Mat image0,image1,new_image;
    double w,h,eps=1e-7;
    
    struct nose{
        double x;
        double y;
        int X;
        int Y;
    }a[100];
    
    void in(int &x){
        int y=1;char c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
        while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
        x*=y;
    }
    void o(int x){
        if(x<0){p('-');x=-x;}
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    
    double get_x(double x,double y){
        double r=sqrt(x*x+y*y);
        if(r-1.0>=eps) return x;
        double theta=(1.0-r)*(1.0-r);
        return cos(theta)*x-sin(theta)*y;
    }
    
    double get_y(double x,double y){
        double r=sqrt(x*x+y*y);
        if(r-1.0>=eps) return y;
        double theta=(1.0-r)*(1.0-r);
        return sin(theta)*x+cos(theta)*y;
    }
    
    signed main(){
        image0 = imread("/Users/war/Downloads/Lisa.png");
        new_image = Mat::zeros(image0.size(), image0.type());
        w=(double)image0.cols*0.5;
        h=(double)image0.rows*0.5;
        For(i,0,image0.rows-1)
            For(j,0,image0.cols-1){
                a[0].x=(i-h)/h;a[0].y=(j-w)/w;
                a[1].x=get_x(a[0].x,a[0].y);
                a[1].y=get_y(a[0].x,a[0].y);
                a[1].x=a[1].x*h+h;
                a[1].y=a[1].y*w+w;
                For(k,0,2){
                    auto t0=image0.at<Vec3b>(floor(a[1].x),floor(a[1].y))[k];
                    auto t1=image0.at<Vec3b>(floor(a[1].x),ceil(a[1].y))[k];
                    auto t2=image0.at<Vec3b>(ceil(a[1].x),floor(a[1].y))[k];
                    auto t3=image0.at<Vec3b>(ceil(a[1].x),ceil(a[1].y))[k];
                    auto t4=(1.0-(a[1].y-floor(a[1].y)))*t0+(a[1].y-floor(a[1].y))*t1;
                    auto t5=(1.0-(a[1].y-floor(a[1].y)))*t2+(a[1].y-floor(a[1].y))*t3;
                    auto t6=(1.0-(a[1].x-floor(a[1].x)))*t4+(a[1].x-floor(a[1].x))*t5;
                    new_image.at<Vec3b>(i, j)[k] = t6;
                }
            }
        imshow("background", new_image);
        waitKey(0);
        return 0;
    }

  • 相关阅读:
    Educational Codeforces Round 97 (Rated for Div. 2)
    2020 计蒜之道 线上决赛
    kuangbin 莫队专题
    Codeforces Round #677 (Div. 3)
    Codeforces Round #674 (Div. 3)
    Elasticsearch Alias:别名
    Elasticsearch 集群重要配置的修改
    Elasticsearch文档版本冲突原理与解决
    redis操作详情
    对密码必须包含字母,数字,特殊字符正则表达式理解
  • 原文地址:https://www.cnblogs.com/war1111/p/13768543.html
Copyright © 2020-2023  润新知