我寫這段代碼來實時檢測使用opencv4android的功能。但不知何故,這段代碼不起作用,我找不到這個代碼中的錯誤,但我猜錯誤的代碼是{detector.detect(mRgba,keypoints)}。我很抱歉我的糟糕解釋。我對這個主題很陌生。請幫幫我。我使用openCV4Android的功能檢測代碼不起作用?
public class MainActivity extends Activity implements CvCameraViewListener2{
private CameraBridgeViewBase mOpenCvCameraView;
private static final String TAG = "feature detection";
private Mat mRgba, mGray;
private FeatureDetector detector;
private DescriptorExtractor SurfExtractor;
private MatOfKeyPoint keypoints;
BaseLoaderCallback blc = new BaseLoaderCallback(this) {
public void onManagerConnected(int status) {
if(status == LoaderCallbackInterface.SUCCESS){
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
mOpenCvCameraView.setCameraIndex(0);
}else{
super.onManagerConnected(status);
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.cam);
mOpenCvCameraView.setCvCameraViewListener(this);
}
@Override
protected void onResume() {
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this,blc);
}
@Override
protected void onPause() {
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public void onDestroy() {
super.onDestroy();
mOpenCvCameraView.disableView();
}
@Override
public void onCameraViewStarted(int width, int height) {
mRgba = new Mat(width, height, CvType.CV_8SC4);
detector = FeatureDetector.create(FeatureDetector.ORB);
SurfExtractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
}
@Override
public void onCameraViewStopped() {
mRgba.release();
}
@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
detector.detect(mRgba, keypoints);
Features2d.drawKeypoints(mRgba, keypoints, mRgba);
return mRgba;
}
}
和錯誤是? – berak
它給出空指針eception。 – user3719132
以上實際檢測到的是什麼? –