利用Mask将不规则区域保存下来
Point2f pt1, pt2, pt3, pt4; pt1.x = 17; pt1.y = 75; pt2.x = 374; pt2.y = 48; pt3.x = 44; pt3.y = 249; pt4.x = 394; pt4.y = 234; line(img, pt1, pt2, Scalar(0,0,255),1); line(img, pt1, pt3, Scalar(0,0,255),1); line(img, pt2, pt4, Scalar(0,0,255),1); line(img, pt3, pt4, Scalar(0,0,255),1); Point2i pts[4] = {Point2i(17,75),Point2i(374,48),Point2i(394,234),Point2i(44,249)}; Mat result(img.size(),CV_8UC1,Scalar(0)); fillConvexPoly(result,pts,4,Scalar(255,255,255)); Mat mask; img.copyTo(mask,result); imshow("mask",mask);