opencv - How to get the vertices of detected rectangle in an image -
opencv - How to get the vertices of detected rectangle in an image -
i new opencv , need observe rectangle in image, vertices , using points, have crop image. rectangle detected finding contours. want vertices (corner values). can please guide or share code?
my code is:
cvseq* contours; //hold pointer contour in memory block cvseq* result; //hold sequence of points of contour cvmemstorage *storage = cvcreatememstorage(0); //storage area contours //finding contours in image cvfindcontours(imggrayscale, storage, &contours, sizeof(cvcontour), cv_retr_list, cv_chain_approx_simple, cvpoint(0,0)); //iterating through each contour while(contours) { //obtain sequence of points of contour, pointed variable 'contour' result = cvapproxpoly(contours, sizeof(cvcontour), storage, cv_poly_approx_dp, cvcontourperimeter(contours)*0.02, 0); //if there 4 vertices in contour(it should rectangle) if(result->total==4 ) { //iterating through each point cvpoint *pt[4]; for(int i=0;i<4;i++) { pt[i] = (cvpoint*)cvgetseqelem(result, i); } //drawing lines around rectangle cvline(img, *pt[0], *pt[1], cvscalar(0,255,0),4); cvline(img, *pt[1], *pt[2], cvscalar(0,255,0),4); cvline(img, *pt[2], *pt[3], cvscalar(0,255,0),4); cvline(img, *pt[3], *pt[0], cvscalar(0,255,0),4); } //obtain next contour contours = contours->h_next; }
opencv rectangles vertices
Comments
Post a Comment