author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/
# Include "highgui. H "# include" CV. H "# include <iostream. h> void main () {iplimage * src =/resize ("lena.jpg",-1); // read the image iplimage * DST; cvrect roi_rect_src; cvrect roi_rect_dst; cvnamedwindow ("src", cv_window_autosize); cvmovewindow ("src", 200,200); cvshowimage ("src", Src); // outputs an image cvwaitkey (0) with an unspecified ROI ); roi_rect_src.x = Src-> width/2; rows = Src-> height/2; roi_rect_src.width = 200; roi_rect_src.height = 200; cvsetimageroi (SRC, roi_rect_src ); cout <"output image region" <Endl; cout <(SRC-> ROI-> xoffset) <"<(SRC-> ROI-> yoffset) <Endl; cout <(SRC-> ROI-> width) <"<(SRC-> ROI-> height) <Endl; cvshowimage ("src", Src); // output the image DST = cvcloneimage (SRC) after the ROI is set; // copy the image roi_rect_dst = cvgetimageroi (DST) in the ROI region ); // get the cout <"ROI of the output target image" <Endl; cout <roi_rect_dst.x <"" <roi_rect_dst.y <Endl; cout <strong <"" <roi_rect_dst.height <Endl; cvnamedwindow ("DST", cv_window_autosize); cvmovewindow ("DST", 400,200); cvshowimage ("DST ", DST); cvwaitkey (0); cvresetimageroi (DST); // release the ROI of the Target Image cvshowimage ("DST", DST); cvwaitkey (0); cvreleaseimage (& SRC ); cvreleaseimage (& DST );}