c++ - How to reduce the noise and enhance the appearance? -
i using visual 2010 (c++) opencv 2.3.1 construct code background subtraction using mog2. shown in full code here works noise.
can suggest on how reduce noise. 1 (thanks him) has told me increase size of kernel instead of using morphological function:
void morphops(mat &thresh){ mat erodeelement = getstructuringelement( morph_rect,size(2,2)); //3x3 mat dilateelement = getstructuringelement( morph_rect,size(1,1)); //8x8 erode(thresh,thresh,erodeelement); erode(thresh,thresh,erodeelement); dilate(thresh,thresh,dilateelement); dilate(thresh,thresh,dilateelement); }
but not know how because still beginner. 1 (thanks him) has suggested solving contours problem noticed if run code "two tips. seems taking 1 point many contours. try averaging them. damp on time. example damped_x=damped_x*0.9+real_x*0.1; part not know how it.
you can see portion of code containing contours in following section, intentionally used have blobs on other smaller objects moving because used instruction track biggest object ( not choice couldnt make track bound them blobs instead).
//find contour contourimg = binaryimage.clone(); //less blob delete vector< vector< point> > contours; findcontours(contourimg, contours, // vector of contours cv_retr_external, // retrieve external contours cv_chain_approx_none); // pixels of each contours vector< rect > output; vector< vector< point> >::iterator itc= contours.begin(); while (itc!=contours.end()) { //create bounding rect of object //rect draw on origin image rect mr= boundingrect(mat(*itc)); rectangle(frame, mr, cv_rgb(255,0,0)); ++itc; }
this instruction select biggest object tracked:
void searchformovement(mat binaryimage, mat &framein){ bool objectdetected = false; mat temp; binaryimage.copyto(temp); vector< vector<point> > contours; vector<vec4i> hierarchy; findcontours(temp,contours,hierarchy,cv_retr_external,cv_chain_approx_simple );// retrieves external contours //if contours vector not empty, have found objects if(contours.size()>0)objectdetected=true; else objectdetected = false; if(objectdetected){ //the largest contour found @ end of contours vector //we assume biggest contour object looking for. vector< vector<point> > largestcontourvec; largestcontourvec.push_back(contours.at(contours.size()-1)); //make bounding rectangle around largest contour find centroid objectboundingrectangle = boundingrect(largestcontourvec.at(0)); int xpos = objectboundingrectangle.x+objectboundingrectangle.width/2; int ypos = objectboundingrectangle.y+objectboundingrectangle.height/2; //update objects positions changing 'theobject' array values theobject[0] = xpos , theobject[1] = ypos; } //make temp x , y variables dont have type out int x = theobject[0]; int y = theobject[1]; //draw crosshairs around object circle(framein,point(x,y),20,scalar(0,255,0),2); line(framein,point(x,y),point(x,y-25),scalar(0,255,0),2); line(framein,point(x,y),point(x,y+25),scalar(0,255,0),2); line(framein,point(x,y),point(x-25,y),scalar(0,255,0),2); line(framein,point(x,y),point(x+25,y),scalar(0,255,0),2); //write position of object screen puttext(framein,"tracking object @ (" + inttostring(x)+","+inttostring(y)+")",point(x,y),1,1,scalar(255,0,0),2); file_ <<"x:"<<inttostring(x)<<" "<<"y:"<<inttostring(y)<<"\n"; }
could guys me . in advance.
Comments
Post a Comment