我试图在屏幕上画一个圆圈,这样它就可以在任何Android设备上扩展,而不管设备大小如何。但由于某种原因,我无法在屏幕中心精确绘制圆圈。这是我到目前为止所尝试的。
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mrgba = inputFrame.rgba();
// Imgproc.cvtColor(mrgba,mgray,Imgproc.COLOR_RGB2GRAY);
// Imgproc.Canny(mgray,mcanny,50,150);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
Imgproc.circle (
mrgba, //Matrix obj of the image
new Point(dpWidth*0.5,dpHeight*0.5), //Center of the circle
10, //Radius
new Scalar(0, 0, 255), //Scalar object for color
10 //Thickness of the circle
);
return mrgba;
}
答案 0 :(得分:0)
要使用OpenCV在屏幕中心绘制一个圆圈,请不要使用DisplayMetrics
,而是使用Mat.height()
和Mat.width()
:
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mrgba = inputFrame.rgba();
Imgproc.circle (
mrgba, //Matrix obj of the image
new Point(mrgba.width() * 0.5,mrgba.height() * 0.5), //Center of the circle
10, //Radius
new Scalar(0, 0, 255), //Scalar object for color
10 //Thickness of the circle
);
return mrgba;
}
以防
<org.opencv.android.JavaCameraView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
甚至更好地从width
参数得到height
和onCameraViewStarted()
:
@Override
public void onCameraViewStarted(int width, int height) {
mWidth = width;
mHeight = height;
}