Open Yogeshvasu opened 6 months ago
hello i am trying to detect the aruco marker but i am getting error No implementation found for long org.opencv.aruco.Aruco.getPredefinedDictionary based on my code
package com.example.opencv_aruco;
import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.WindowManager; import android.widget.Button; import android.widget.Toast;
import org.opencv.android.BaseLoaderCallback; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.aruco.Aruco; import org.opencv.aruco.Dictionary; import org.opencv.core.Mat; import org.opencv.core.MatOfInt; import org.opencv.core.Scalar; import org.opencv.imgproc.Imgproc;
import java.util.ArrayList; import java.util.List;
public class MainActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener2 {
private static final String TAG = "MainActivity"; private CameraBridgeViewBase mOpenCvCameraView; private Dictionary mDictionary; private MatOfInt mIds; private List<Mat> mCorners; private boolean isDetecting = false; private Button btnDetectMarker; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: Log.i(TAG, "OpenCV loaded successfully"); mOpenCvCameraView.enableView(); break; default: super.onManagerConnected(status); break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.activity_main); mOpenCvCameraView = findViewById(R.id.camera_view); mOpenCvCameraView.setVisibility(CameraBridgeViewBase.VISIBLE); mOpenCvCameraView.setCvCameraViewListener(this); btnDetectMarker = findViewById(R.id.btn_detect_marker); btnDetectMarker.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { isDetecting = true; } }); mDictionary = Aruco.getPredefinedDictionary(Aruco.DICT_5X5_50); mIds = new MatOfInt(); mCorners = new ArrayList<>(); } @Override protected void onResume() { super.onResume(); if (OpenCVLoader.initDebug()) { Log.d(TAG, "OpenCV initialization succeeded"); mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS); } else { Log.d(TAG, "OpenCV initialization failed"); Toast.makeText(this, "OpenCV initialization failed", Toast.LENGTH_LONG).show(); } } @Override protected void onPause() { super.onPause(); if (mOpenCvCameraView != null) mOpenCvCameraView.disableView(); } @Override protected void onDestroy() { super.onDestroy(); if (mOpenCvCameraView != null) mOpenCvCameraView.disableView(); } @Override public void onCameraViewStarted(int width, int height) { } @Override public void onCameraViewStopped() { } @Override public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) { Mat frame = inputFrame.rgba(); if (isDetecting) { Mat gray = inputFrame.gray(); mIds = new MatOfInt(); mCorners.clear(); // Detect markers Aruco.detectMarkers(gray, mDictionary, mCorners, mIds); // Draw markers and measure width and height if (mIds.total() > 0) { Aruco.drawDetectedMarkers(frame, mCorners, mIds, new Scalar(255, 0, 0)); for (Mat corners : mCorners) { if (corners.rows() == 1 && corners.cols() == 4) { for (int i = 0; i < 4; i++) { Imgproc.line(frame, new org.opencv.core.Point(corners.get(0, i)), new org.opencv.core.Point(corners.get(0, (i + 1) % 4)), new Scalar(0, 255, 0), 2); } double width = Math.sqrt(Math.pow(corners.get(0, 0)[0] - corners.get(0, 1)[0], 2) + Math.pow(corners.get(0, 0)[1] - corners.get(0, 1)[1], 2)); double height = Math.sqrt(Math.pow(corners.get(0, 1)[0] - corners.get(0, 2)[0], 2) + Math.pow(corners.get(0, 1)[1] - corners.get(0, 2)[1], 2)); Log.d(TAG, "Width: " + width + ", Height: " + height); } } } // Reset the flag isDetecting = false; } return frame; }
}
Hello,
You need to add native libraries, see this documentation
hello i am trying to detect the aruco marker but i am getting error No implementation found for long org.opencv.aruco.Aruco.getPredefinedDictionary based on my code
package com.example.opencv_aruco;
import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.WindowManager; import android.widget.Button; import android.widget.Toast;
import org.opencv.android.BaseLoaderCallback; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.aruco.Aruco; import org.opencv.aruco.Dictionary; import org.opencv.core.Mat; import org.opencv.core.MatOfInt; import org.opencv.core.Scalar; import org.opencv.imgproc.Imgproc;
import java.util.ArrayList; import java.util.List;
public class MainActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener2 {
}