首页 > 其他 > 详细

实验3.2

时间:2020-10-04 22:44:53      阅读:49      评论:0      收藏:0      [点我收藏+]
#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;
}

 

 

技术分享图片

 

 

 

 

技术分享图片

 

实验3.2

原文:https://www.cnblogs.com/war1111/p/13768581.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!