Using camera_id-tag in layout XML forces crash on Nexus 7 (Bug #3032)


Added by Christopher Schott almost 12 years ago. Updated almost 12 years ago.


Status:Cancelled Start date:2013-05-17
Priority:Normal Due date:2013-05-17
Assignee:Alexander Smorkalov % Done:

0%

Category:android
Target version:2.4.6
Affected version:2.4.5 (latest release) Operating System:
Difficulty: HW Platform:
Pull request:

Description

Hi Guys,

I created the following layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".VideoActivity" >

&lt;org.opencv.android.JavaCameraView
android:id="@+id/viewVideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
custom:camera_id="front"
custom:show_fps="true" />

</LinearLayout>

Important is the Option custom:camera_id="front". If I run my app on a usual smartphone which has both - front and back camera - my app runs perfectly and uses the front camera. But if I run my application on a Nexus 7 - which has only a front camera - I got the following error:

On Display:
It seems that you devices does not support camera (or it is locked). Application will be closed.

On LogCat:
05-17 09:03:34.997: E/JavaCameraView(4410): Camera #1failed to open: Fail to connect to camera service

As a matter of fact the Nexus 7 only has a front camera, which has the camera-id = 0.
I think instead of opening the camera #1 as front camera in a fixed way the options from Camera.CameraInfo-class should be considered (CAMERA_FACING_BACK, CAMERA_FACING_FRONT). http://developer.android.com/reference/android/hardware/Camera.CameraInfo.html
I mean something like this:
/** * Opens the front camera. * * @return the front camera object or null if none.
*/
public static Camera getCameraInstance(){
// Open front camera:
final CameraInfo cameraInfo = new CameraInfo();
for (int i = 0; i < Camera.getNumberOfCameras(); i++){
Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT){
return Camera.open(i);
}
}
return null;
}

I also added an Android project which shows this issue.


CameraError.zip - Android Project demonstrating this issue on Nexus 7 only (1.4 MB) Christopher Schott, 2013-05-17 09:14 am


Related issues

related to Bug #2839: OpenCV Android Getting Front Camera From JavaCameraView Done 2013-02-27

Associated revisions

Revision 432b7cb2
Added by Vadim Pisarevsky over 10 years ago

Merge pull request #3032 from vpisarev:refactor_ml2

History

Updated by Alexander Smorkalov almost 12 years ago

Issue has been already fixed in related ticket. Fix will be published with the next release.

  • Status changed from Open to Cancelled

Also available in: Atom PDF