实验1.3

#include <bits/stdc++.h>
#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.9.15
using namespace std;
using namespace cv;
uchar b[10000010];
Mat image0,image1,temp,temp0;
vector<Mat> v;
int pos;
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');
}

uchar*  get_pixel(const uchar *img, int x, int y,int step){
        return (uchar*)(img+y*step+x*3);
}


void getChannel(const uchar *input, int width, int height, int inStep, int inChannels,  int channelToGet ){
    pos=0;
    For(i,0,height-1)
        For(j,0,width-1){
            auto k=get_pixel(input,j,i,inStep);
            b[pos++]=*(k+channelToGet);
        }
}


signed main(){
    For(i,0,2){
        image0=imread("/Users/war/Downloads/dog.PNG");
        v.clear();
        temp = image0(Rect(700,700,700,700));
        For(i,1,3) v.push_back(Mat::zeros(temp.cols, temp.rows, CV_8UC1));
        getChannel(temp.data, temp.cols, temp.rows, (int)temp.step, temp.channels(),i);
        Mat image (temp.cols, temp.rows, CV_8UC1, b, temp.cols);
        v[i]=image;
        merge(v,image);
        image.copyTo(image0(Rect(300,300,700,700)));
        imshow("dog",image0);
        waitKey(-1);
    }
    imshow("dog",image0);
    waitKey(-1);
    return 0;
}

 

原文地址:https://www.cnblogs.com/war1111/p/13676407.html