c++ function call by value not work -
i have problem code:
the problem when see image original, modified "borrarfondo()" function called "segmentarhoja" , here entry img value, img modifies.
void borrarfondo(mat& img){ img = ~img; mat background; medianblur(img, background, 45); gaussianblur(background, background, size(203,203),101,101); img = img - background; img = ~img; } void segmentarhoja(mat img, mat& imsheet){ mat imgbw; borrarfondo(img); //borrarfondo called here img copy cvtcolor(img, imgbw, cv_bgr2gray); threshold(imgbw, imgbw, 0, 255, cv_thresh_binary | cv_thresh_otsu); mat element = getstructuringelement(morph_ellipse, size(21,21)); erode(imgbw, imgbw, element); vector<vector<point> > contourssheet; findcontours(imgbw, contourssheet, cv_retr_ccomp, cv_chain_approx_simple); vector<rect> boundsheet(contourssheet.size()); int largest_area=0; for( int = 0; i< contourssheet.size(); i++ ) { double a= contourarea( contourssheet[i],false); if(a>largest_area){ largest_area=a; boundsheet[i] = boundingrect(contourssheet[i]); imsheet=img(boundsheet[i]).clone(); } } borrarfondo(imsheet); } int main() { mat imsheet; image= imread("c:/imagen.jpg"); segmentarhoja(image, imsheet); imshow("imsheet",imsheet); imshow("imagen",image); //original image amending borrarfondo waitkey(0); }
i don't want change original image
opencv mat
counted reference (i.e. std::shared_ptr
, except different syntax) copy construction or assignment not copy. use clone
method copy. read the documentation, idea.
Comments
Post a Comment