c++ - Converting contours from vector of cv::Point in cv::Mat -
suppose objective extract contours initial image. performed operations using opencv:
cv::mat gray, edges; cv::cvtcolor(image, gray, cv_bgra2gray); cv::canny(gray, edges, 100, 300, 3); std::vector<std::vector<cv::point>> contours; std::vector<cv::vec4i> hierarchy; cv::findcontours(edges, contours, hierarchy, cv::retr_tree, cv::chain_approx_simple, cv::point(0, 0)); now contour contained in array of points. want rebuild cv::mat structure having same dimensions initial image, emphasize contour superimposing image.
in particular, not interested in drawing contour. perform following operations:
- extract contour
- dilate contour
- superimpose contour on image (as in edge sharpening)
thus, contour has matrix of same size of input image.
how can that?
thanks in advance.
you can re-built matrix
mat image_contours_grayscale = mat::zeros(gray.size(),gray.type()); scalar color(255); drawcontours( image_contours_grayscale, contours,-1,color,1); i'm not sure if drawcontours works grayscale image, if doesn't, can try
mat image_contours_color = mat::zeros(image.size(),image.type()); scalar color(255,255,255); drawcontours( image_contours_color, contours,-1,color,1); mat image_contours_grayscale; cv::cvtcolor(image_contours_color, image_contours_grayscale, cv_bgra2gray); image_contours_grayscale should grayscale image, black contours in white.
let me know if works, didn't have occasion test solution !
Comments
Post a Comment