2

I'm trying to move a very simple OpenCV application to android. The code tries to access the camera from a C++ .so library that is linked with the main app which is using C# and Xamarin which I doubt has anything to do with my issue. My C++ code simply tries to access the camera using cv::VideoCapture like so:

    cv::VideoCapture cap(0); //default camera

    if(!cap.isOpened())
    {
        LOGE("No camera detected on this system\n");
    }

This however always fails despite me specifying permission in AndroidManifest.xml like so:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.XamarinARapp">
  <uses-sdk android:minSdkVersion="15" />
  <application android:label="XamarinARapp.Android">
  </application>
  <uses-permission android:name="android.permission.CAMERA"/>
  <uses-feature android:name="android.hardware.camera" android:required="false"/>
  <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
  <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
  <uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>
</manifest>

Has anyone been successful accessing the android camera with cv::VideoCapture in C++? Does Xamarin have anything to do with it?

3
  • What Android API version are you testing on? i.e. Have you requested runtime camera permission in your code for API level 23+ devices? Commented Mar 6, 2018 at 19:31
  • I'm testing on on android 8.0 Nexus 5X but the app is being built for android 4.4 Commented Mar 6, 2018 at 20:11
  • I see a min. target API listed in your manifest.... What about the target? Commented Mar 6, 2018 at 20:13

1 Answer 1

2

but the app is being built for android 4.4

Your manifest SDK versions should look like this:

<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" />

Otherwise without the targetSdkVersion set and running on a API 23+ device you will need to request runtime camera permissions.

Sign up to request clarification or add additional context in comments.

1 Comment

I modified my code to request run-time camera permissions using the Xamarin Plugin.Permissions, and the permissions are definitely being granted, however the issue persists. Changed both minSdkVersion and targetSdkVersion to 24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.