Ask Your Question

Revision history [back]

// i wrote this code to train myself about this question. maybe it will be useful for newcomers like me    
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <iostream>

    using namespace cv;
    using namespace std;

    int main( )
    {

        Mat image(400,300,CV_8UC1,Scalar(200,200,200));

        Rect newroi;
        newroi.width=image.cols*0.9;
        newroi.height=image.rows*0.9;
        newroi.x=image.cols*0.05;
        newroi.y=image.rows*0.05;


        rectangle(image,newroi,Scalar(0,0,0),1);
        Mat newimage=image(newroi);

        namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
        imshow( "Display window", image );

        namedWindow( "Display window2", WINDOW_AUTOSIZE );// Create a window for display.
        imshow( "Display window2", newimage );

        waitKey(0);                                          // Wait for a keystroke in the window
        return 0;
    }

        enter code here
// 

i wrote this code to train myself about this question. maybe it will be useful for newcomers like me #include <opencv2/core/core.hpp> ( Edited according to StevenPuttemans's advice

#include <opencv2/highgui/highgui.hpp>
 #include <iostream>
<opencv2/imgproc/imgproc.hpp>
using namespace cv;
 using namespace std;
int main( )

Mat shrinkMat(Mat src,int percent,bool clone=false)
{

Mat image(400,300,CV_8UC1,Scalar(200,200,200));
 if (percent>99)
return src;
 Rect newroi;
 newroi.width=image.cols*0.9;
newroi.height=image.rows*0.9;
newroi.x=image.cols*0.05;
newroi.y=image.rows*0.05;
rectangle(image,newroi,Scalar(0,0,0),1);
newroi.width=(src.cols*percent)/100;
newroi.height=(src.rows*percent)/100;
newroi.x=(src.cols-newroi.width)/2;
newroi.y=(src.rows-newroi.height)/2;
if (clone) return src(newroi).clone();
return src(newroi);
}
int main()
{
 Mat newimage=image(newroi);
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window image(600,800,CV_8UC3,Scalar(220,220,220));
Mat newimage;
for display.
(int i=2; i<99; i+=10)
{
newimage=shrinkMat(image,i);
rectangle(newimage,Rect(0,0,newimage.cols,newimage.rows),Scalar(rand()&255,rand()&255,rand()&255),3);
}
newimage=shrinkMat(image,45);
ellipse( newimage, Point(newimage.cols/2,newimage.rows/2), Size( newimage.cols/2, newimage.rows/2), 0, 0, 360, Scalar( 255, 0, 0 ), 2, 8, 0 );
newimage=shrinkMat(image,75,true);
ellipse( newimage, Point(newimage.cols/2,newimage.rows/2), Size( newimage.cols/2, newimage.rows/2), 0, 0, 360, Scalar( 255, 0, 0 ), 2, 8, 0 );
 imshow( "Display window", window1", image );

namedWindow( "Display window2", WINDOW_AUTOSIZE );// Create a window for display.
 imshow( "Display window2", newimage );
 waitKey(0); // Wait for a keystroke in the window
waitKey(0);
 return 0;
 }

enter code here