ImagemView being positioned in the preview camera
I'm having problems when trying to position a imageView in JavaCameraView. I am using a ImagemView Instead of using a Mat to gain performance as it has a png image to be fixed around the eyes. I managed to locate opencv and have the eye area and can draw the area:
Core.rectangle(mRgba, eyeArea.tl(), eyeArea.br(),
new Scalar(255, 0, 0, 255), 2);
But when trying to position and resize the ImagemView nothing is being right. Even catching the eye area position the ImageView is smaller and off the correct location and that the command above this drawing correctly. I saw that the JavaCameraView its size is different from the frame shown, I could adjust the ImageView the container to the same size frame but still there are problems in ImageView ...
Fix container size and position of the ImageView:
RelativeLayout rlMaskContainer = (RelativeLayout) findViewById(R.id.rlMaskContainer);
rlMaskContainer.getLayoutParams().height
= mOpenCvCameraView.dstRect.height();
rlMaskContainer.getLayoutParams().width
= mOpenCvCameraView.dstRect.width();
rlMaskContainer.setX(mOpenCvCameraView.dstLeftRect);
rlMaskContainer.setY(mOpenCvCameraView.dstTopRect);
Resize and positioning ImageView by EyeArea Rect:
runOnUiThread(new Runnable() {
@Override
public void run() {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(eyeArea.width, eyeArea.height);
params.leftMargin = eyeArea.x;
params.topMargin = eyeArea.y;
ivMask.setLayoutParams(params);
ivMask.setScaleType(ImageView.ScaleType.FIT_XY);
} });
Preview Camera (Red area is container RelativeLayout, rectangle is Rect EyeArea):