《学习OpenCV》第三章练习(参考代码)第5题

#include<cv.h>
#include<highgui.h>


int main(int argc, char** argv){
    IplImage* img = cvCreateImage(cvSize(210, 210), IPL_DEPTH_8U, 3);
    cvZero(img);
    int borderWidth = 10;
    int offsetX = 10;
    int offsetY = 10;
    int centerX = img->width/2-borderWidth;
    int centerY = img->height/2-borderWidth;
    int x = 5;
    int y = 5;
    int rectWidth = 90;
    int rectHeight = 90;
    int color = 75;
    do{
        cvSetImageROI(img, 
          cvRect(x, y, rectWidth*2+borderWidth*2, rectHeight*2+borderWidth*2)
        );
        cvSet(img, cvScalar(color, color, color));
        cvResetImageROI(img);
        x+=offsetX;
        y+=offsetY;
        rectWidth-=offsetX;
        rectHeight-=offsetY;
        color+=20;
    }while(x < centerX && y < centerY);

    cvNamedWindow("pyramid", CV_WINDOW_AUTOSIZE);
    cvShowImage("pyramid", img);
    cvWaitKey(0);
    cvReleaseImage(&img);
    cvDestroyWindow("pyramid");
}

你可能感兴趣的:(opencv,opencv,练习,learning,第三章,答案,学习OpenCV,课后习题答案,第5题,第五题)