#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(1.5*theta)*x; } 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 cos(1.5*theta)*y; } signed main(){ VideoCapture capture(0); while(1){ capture >> image0; if(image0.empty())continue; 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); if(waitKey(20) == 'q') break; } capture.release(); destroyAllWindows(); return 0; }