android - OpenCV4Android Circular Object Tracking -
i new opencv
, trying track circular object using find contours on android using 3.1.0. following sample color blob detector write code, drawcontours()
function never draws when run application. here oncameraframe()
function, doing processing. can tell me doing wrong?
edit: new version of code: still not work expected. drawcontours() draws around black objects, , function produces noisy result. here looks like.
public mat oncameraframe(cvcameraviewframe inputframe) { mat rgba = inputframe.rgba(); mat graymat = new mat(); imgproc.cvtcolor(rgba, graymat, imgproc.color_rgba2gray); mat processedmat = new mat(); imgproc.threshold(graymat, processedmat, 0, 255, imgproc.thresh_binary); list<matofpoint> contours = new arraylist<matofpoint>(); list<matofpoint> matchedcontours = new arraylist<matofpoint>(); mat hierarchy = new mat(); imgproc.findcontours(processedmat, contours, hierarchy, imgproc.retr_list, imgproc.chain_approx_simple); for(matofpoint contour : contours){ double actualarea = imgproc.contourarea(contour); double width = contour.width(); double radius = width/2; double calculatedarea = math.pi * math.pow(radius, 2); if((actualarea - calculatedarea) < 10000) { //chose arbitrary threshold because not sure make matchedcontours.add(contour); } } imgproc.drawcontours(rgba, matchedcontours, -1, new scalar(0,255,0)); return rgba; }
Comments
Post a Comment