#include <opencv2/highgui/highgui.hpp> #include <stdio.h>int main () { iplimage *image1; Iplroi ROI; Cvrect Rect1,rect2; Image1=cvloadimage ("sunspot. jpg", 1); Rect1=cvrect (50,50,14,22);//coordinate value according to manual calibration to determine roi=cvrecttoroi (rect1,0); image1->roi=&roi; Rect2=cvroitorect (*image1->roi); Cvnamedwindow ("Coast (Region of Interesting)", 1); Cvshowimage ("Coast (Region of Interesting)", Image1); image1->roi=null; Cvrectangle (Image1,cvpoint (50,50), Cvpoint (+ 14,50 +), Cv_rgb (255,0,0), 1,8,0); Cvnamedwindow ("Coast", 1); Cvshowimage ("Coast", Image1); Cvwaitkey (0);}
#include "opencv2/highgui/highgui.hpp" #include "iostream" using namespace std;using namespace cv; void Main () { iplimage *src=cvloadimage ("sunspot. jpg",-1);//read in image iplimage *dst; Cvrect roi_rect_src; Cvrect ROI_RECT_DST; Cvnamedwindow ("src", cv_window_autosize); Cvmovewindow ("src", 200,200); cvshowimage ("src", src);//Output an image of the non-locating ROI cvwaitkey (0); roi_rect_src.x=src->width/2; roi_rect_src.y=src->height/2; roi_rect_src.width=200; roi_rect_src.height=200; Cvsetimageroi (SRC,ROI_RECT_SRC); cout<< "output image area" <<endl; cout<< (src->roi->xoffset) << "<< (src->roi->yoffset) <<endl ; cout<< (Src->roI->width) << "<< (src->roi->height) <<endl; <span style=" White-space:pre "> </span>cvnamedwindow ("Src1", cv_window_autosize); cvshowimage ("Src1", SRC);//output set image after Roi Dst=cvcloneimage (SRC);//Copy the image of the ROI region Roi_rect_dst=cvgetimageroi (DST); /Get ROI area of image cout<< "ROI of output target image" <<endl; cout<<roi_rect_dst.x<< "" <<ROI_rect_dst.y<<endl; cout<<roi_rect_dst.width<< "" <<ROI_rect_dst.height<<endl; Cvnamedwindow ("DST", cv_window_autosize); Cvmovewindow ("DST", 400,200); Cvshowimage ("DST", DST); Cvwaitkey (0); Cvresetimageroi (DST);//release ROI cvshowimage ("DST", DST) for the target image; Cvwaitkey (0); Cvreleaseimage (&SRC); Cvreleaseimage (&DST); }
Opencv_roi Select areas of interest draw rectangles on the original and show ROI and applications