zoukankan      html  css  js  c++  java
  • 实验8.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 100010
    #define p(a) putchar(a)
    #define For(i,a,b) for(int i=a;i<=b;++i)
    //by war
    //2020.10.27
    using namespace std;
    using namespace cv;
    int n,k,cnt,lim,r;
    int t[510][510][251];
    Mat image,img0,out;
    struct ki{
        int x;
        int y;
    }a[N];
    
    struct node{
        int x;
        int y;
        int r;
        int cnt;
        bool operator < (const node & k) const{
            return cnt<k.cnt;
        }
    }temp;
    
    priority_queue<node,vector<node>,less<node> >q;
    
    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');
    }
    
    signed main(){
        img0 = imread("/Users/war/Downloads/test8/7.jpg",0);
        //cvtColor(img0, img0, COLOR_RGB2GRAY);
        GaussianBlur(img0,img0,Size(3,3),1);
        Canny(img0,img0,50,200,3);
        cnt=0;
        For(i,0,img0.rows-1)
            For(j,0,img0.cols-1){
                if((int)img0.at<Vec3b>(i,j)[0]!=0){
                   a[++cnt].y=i;
                   a[cnt].x=j;
                }
            }
        lim=0;
        For(i,0,img0.rows-1)
            For(j,0,img0.cols-1){
                For(k,1,cnt){
                    r=sqrt((a[k].y-i)*(a[k].y-i)+(a[k].x-j)*(a[k].x-j));
                    if(r>i || r>j || r>img0.rows-i || r>img0.cols-j) continue;
                    lim=max(lim,r);
                    t[i][j][r]++;
                }
            }
        For(i,0,img0.rows-1)
            For(j,0,img0.cols-1){
                For(k,1,lim){
                    if(t[i][j][k]>0){
                        q.push(node{i,j,k,t[i][j][k]});
                    }
                }
            }
        out = Mat::zeros(img0.rows, img0.cols, img0.type());
        cnt=0;
        in(lim);
        while(!q.empty() && (++cnt)<=lim){
            temp=q.top();q.pop();
            circle(out, Point (temp.y,temp.x), temp.r, Scalar (255, 255, 255), 1, 8, 0);
        }
        imshow("out0",img0);
        imshow("out1",out);
        waitKey();
        return 0;
    }
  • 相关阅读:
    android 多线程
    Uva 10881 Piotr’s Ants 蚂蚁
    LA 3708 Graveyard 墓地雕塑 NEERC 2006
    UVa 11300 Spreading the Wealth 分金币
    UVa 11729 Commando War 突击战
    UVa 11292 The Dragon of Loowater 勇者斗恶龙
    HDU 4162 Shape Number
    HDU 1869 六度分离
    HDU 1041 Computer Transformation
    利用可变参数函数清空多个数组
  • 原文地址:https://www.cnblogs.com/war1111/p/13929150.html
Copyright © 2011-2022 走看看