gpt4 book ai didi

android - OpenCV JavaCameraView 显示空白/黑屏

转载 作者:行者123 更新时间:2023-12-02 16:07:01 43 4
gpt4 key购买 nike

<分区>

作为 Android 开发新手,过去几个月我一直在为 OpenCV 的 JavaCameraView 苦苦挣扎,它总是显示空白/黑屏。我已经在网上关注了很多教程,但是按照它们进行了开球却带来了 0 个结果。我知道我的代码正确加载 OpenCV 并且 Logcat 描述代码尝试启动相机 View ,但无济于事。我需要帮助。代码中有问题的部分是这样的:

public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
//Activate Camera
private BaseLoaderCallback baseLoaderCallback = new BaseLoaderCallback (this) {
@Override
public void onManagerConnected(int status) {
if (status == BaseLoaderCallback.SUCCESS) {
OpenCVCamView.enableView(); //Enable Cam View
Log.d(TAG, "Tried enabling Camera View!");
} else { super.onManagerConnected(status); }
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "on Create");
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main); //UI Layout loaded
OpenCVCamView = findViewById(R.id.cam_view);
textView = findViewById(R.id.arduino_log);
textView.setVisibility(SurfaceView.INVISIBLE);
OpenCVCamView.setVisibility(SurfaceView.VISIBLE);
OpenCVCamView.setCvCameraViewListener(this);
@Override
public void onCameraViewStarted(int width, int height) {
Log.d(TAG, "on Camera view Started");
rgba = new Mat (height, width, CvType.CV_8UC4);
rgbaF = new Mat (height, width, CvType.CV_8UC4);
rgbaT = new Mat (height, width, CvType.CV_8UC4);
intMat = new Mat(height, width, CvType.CV_8UC4);
gray = new Mat (height, width, CvType.CV_8UC1);
}
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
rgba = inputFrame.rgba();
Log.d(TAG, "on Camera Frame");
Core.transpose(rgba,rgbaT);
Imgproc.resize(rgbaT,rgbaF,rgbaF.size(),0,0,0);
Core.flip(rgbaF,rgba,1);
return rgba;
}
}

我的 activity_main XML 文件是这样的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<org.opencv.android.JavaCameraView
android:id="@+id/cam_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
opencv:camera_id="any"/>
<TextView
android:id="@+id/arduino_log"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="0dp"
android:visibility="invisible" />
</RelativeLayout>

我正在使用适用于 Android 的 OpenCV 4.3 版。

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com