logo
down
shadow

Android Camera in Background OpenCV


Android Camera in Background OpenCV

By : user2956015
Date : November 22 2020, 10:48 AM
hop of those help? I have worked with OpenCV and Android Camera. It's not that difficult to begin with. I used JNI to process frames. Things you need to do.
Use android.hardware.Camera Create a class which extends SurfaceHolder.Callback and Camera.PreviewCallback
code :
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
    if (data == null) {
        Log.i(TAG, "data is null");
        return;
    }

    int expectedBytes = previewWidth * previewHeight *
            ImageFormat.getBitsPerPixel(ImageFormat.NV21) / 8;

    if (expectedBytes != data.length) {
        Log.e(TAG, "Mismatched size of buffer! Expected ");

        mState = STATE_NO_CALLBACKS;
        mCamera.setPreviewCallbackWithBuffer(null);
        return;
    }

    if (mProcessInProgress) {
        mCamera.addCallbackBuffer(data);
        return;
    }

    if (mState == STATE_PROCESS) {
        mProcessInProgress = true;

        processDataTask = new ProcessPreviewDataTask();
        processDataTask.execute(data);

    } else {
        mCamera.addCallbackBuffer(data);
        return;
    }

}
private class ProcessPreviewDataTask
        extends
            AsyncTask<byte[], Void, Boolean> {

    @Override
    protected Boolean doInBackground(byte[]... datas) {
        mState = STATE_PROCESS_IN_PROGRESS;
        Log.i(TAG, "background process started");
        byte[] data = datas[0];

        /* JNI Call here */

        mCamera.addCallbackBuffer(data);
        mProcessInProgress = false;
        return true;
    }

    @Override
    protected void onPostExecute(Boolean result) {
        mState = STATE_PROCESS;
        threadInProcess = false;
    }
}


Share : facebook icon twitter icon
Android & OpenCV: Homography to Camera Pose considering Camera Intrinsics and Backprojection

Android & OpenCV: Homography to Camera Pose considering Camera Intrinsics and Backprojection


By : Kymation
Date : March 29 2020, 07:55 AM
may help you . Get it to work on another way. Instead of using findHomography()/getP erspectiveTransform() i found another function called solvePnP() which returns the camera pose based on world and images points and an intrinsic camera matrix.
Using that function in combination with the projectPoints() method - i was able to reproject the 3d points back to the image.
Android OpenCV - How to process camera frames from background service?

Android OpenCV - How to process camera frames from background service?


By : Kouroush Tavana
Date : March 29 2020, 07:55 AM
With these it helps According to the examples of fadden available (have a look here), you can do it using a SurfaceTexture instead of a SurfaceView for getting the frames. It was also answered here before, but unfortunately never validated.
I could get frames from a service this way.
Andriod Studio OpenCV 3.2, Cannot open video file or android camera with native OpenCV

Andriod Studio OpenCV 3.2, Cannot open video file or android camera with native OpenCV


By : MEHDIMYADI
Date : March 29 2020, 07:55 AM
wish helps you I failed to open camera inside Native code, instead I ended up using android OpenCV Camera implementation, opencv.android.CameraBridgeViewBase.
MainActivity.java
code :
public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {

    private CameraBridgeViewBase mCvCamView;
    Mat matInput, matOutput;

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                    mCvCamView.enableView();
                    break;
                default:
                    super.onManagerConnected(status);
                    break;
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mCvCamView = (CameraBridgeViewBase)findViewById(R.id.cam_view);
        mCvCamView.setVisibility(SurfaceView.VISIBLE);
        mCvCamView.setCvCameraViewListener(this);
        mCvCamView.setCameraIndex(1); // front-camera(1),  back-camera(0)
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }

    @Override
    public void onPause()
    {
        super.onPause();
        if (mCvCamView != null)
            mCvCamView.disableView();
    }

    @Override
    public void onResume()
    {
        super.onResume();

        if (!OpenCVLoader.initDebug()) {
            Log.d(TAG, "onResume :: Internal OpenCV library not found.");
            OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_2_0, this, mLoaderCallback);
        } else {
            Log.d(TAG, "onResume :: OpenCV library found inside package. Using it!");
            mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
        }
    }

    public void onDestroy() {
        super.onDestroy();
        if (mCvCamView != null)
            mCvCamView.disableView();
    }

    @Override
    public void onCameraViewStarted(int width, int height) {
        if ( matOutput == null || matOutput.empty() )
            matOutput = new Mat(height, width, CvType.CV_8UC4, new Scalar(255, 0, 0, 255));
    }

    @Override
    public void onCameraViewStopped() {}

    @Override
    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        matInput = inputFrame.rgba();
        Native.extract(matInput.getNativeObjAddr(), matOutput.getNativeObjAddr());
        return matOutput;
    }

}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <org.opencv.android.JavaCameraView
        android:id="@+id/cam_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>
Why on Android, OpenCV camera is faster than the Android Camera when capturing video

Why on Android, OpenCV camera is faster than the Android Camera when capturing video


By : Durgesh
Date : March 29 2020, 07:55 AM
To fix this issue OpenCV uses a hack to get low level access to the Android camera. It allows to avoid several data copyings and transitions between native and managed layers.
Rotate camera preview to Portrait Android OpenCV Camera

Rotate camera preview to Portrait Android OpenCV Camera


By : Ahsan
Date : March 29 2020, 07:55 AM
it helps some times I had the same problem trying to implement OpenCV. I was able to fix it by making the following changes to the deliverAndDrawFrame method.
Related Posts Related Posts :
  • Android Studio gradle build failed for hello world app
  • Slide a layout up from bottom of screen
  • Play HTML5 video in iOS/Android native media player
  • How to rescale a bitmap file in android?
  • No view found for id 0x for fragment after rotation?
  • Define different themable styles to the same widget types
  • ProGuard not working in my app
  • FragmentTransaction from BaseAdapter
  • Connecting multiple devices in a Wifi Direct group
  • Why TabActivity is deprecated in android
  • How to capture low resolution picture using android camera
  • android preferenceactivity padding in landscape orientation
  • How can I store cookie in webview?
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org