c++ - Android + OpenCV: OnTouch getX(), getY() doesn't return right values -
i using opencv4android facedetection sample. have global table rectangles of spoted faces:
private rect[] facesarray;
also global floats store onclick coordinates,
private float onclickx; private float onclicky;
which generated ontouchevent:
@override public boolean ontouchevent(motionevent e) { onclickx = e.getx(); onclicky = e.gety(); switch (e.getaction()) { case motionevent.action_down: // not important matter happens here } return super.ontouchevent(e); }
in oncameraframe method before returning mat view doing:
core.circle(mrgba,new point(onclickx,onclicky), 40, new scalar(0, 255, 0, 255));
so happens. draw small, green circle on coordinates fetched in ontouchevent , sent global variables. variables (onclickx, onclicky) read oncameraframe , used core.circle() function. problem that, circle isn't drawn precisely under finger in lower-right place. happens: https://dl.dropboxusercontent.com/u/108321090/device-2013-07-24-004207.png
and circle in same direction/position finger whenever on screen, , meets in top-left corner, dissapears on bottom right corner (goes outside screen). tried using getrawx, geyrawy -> result same, don't understeand why commands doesn't return precise tap position somewhere near it. have no clue how fix this.
this solution problem.
which is,
@override public boolean ontouch(view arg0,motionevent event) { double cols = mrgba.cols();// mrgba image frame double rows = mrgba.rows(); double xoffset = (mopencvcameraview.getwidth() - cols) / 2; double yoffset = (mopencvcameraview.getheight() - rows) / 2; onclickx = (float)(event).getx() - xoffset; onclicky = (float)(event).gety() - yoffset;
Comments
Post a Comment