I start to write simple app that draw rectangle via opencv4android in place where i touch the screen. The code is similiar than the color-blob-detection tutorial. Rectangle is draw inside onCameraFrame using global object of Rect. Problem is that the rectangle dont show in place where the screen is touched. And its strange but the coords x and y are more different if the touch place is further than the middle of the screen. It looks like this (red circles are touch places, draw rects are green). And this is code of onTouch:
public boolean onTouch(View v, MotionEvent event) {
int cols = mRgb.cols();
int rows = mRgb.rows();
int xOffset = (mOpenCvCameraView.getWidth() - cols) / 2;
int yOffset = (mOpenCvCameraView.getHeight() - cols) / 2;
int x = (int) (event.getX() - xOffset);
int y = (int) (event.getY() - yOffset);
//this is global rect drawing inside onCameraFrame
viewRect.x = x;
viewRect.y = y;
return false;
}
I also try to draw rects by calculating screenratio cameraViewWidth/layoutWidth like i saw on the other posts or another method using getWindowManager().getDefaultDisplay().getMetrics() or using getRawX() method but it is always mismatch. I think the problem is in aspect ratio but cant resolve this. Maybe im sitting on this to long.
Aucun commentaire:
Enregistrer un commentaire