Ask Your Question
3

How I use front camera with new OpenCV 2.4.3 for android?

asked 2012-11-15 13:25:02 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Hello.

I'm developing OpenCV project on Android devices. I adapted my previous code android interface to this new OpenCV 2.4.3. The implementation of CameraBridgeViewBase is nice and has many facilities for beginners, but i can't use the frontal face.

I tested with the permissions and the camera configuration, but I did not succeed.

With the nextcode, it's posible set a new configuration with the frontal camera?

CameraBridgeViewBase mOpenCvCameraView;
OpenCvCameraView = (CameraBridgeViewBase)findViewById(R.id.activity_native_surface_view);    
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);     
mOpenCvCameraView.setCvCameraViewListener(this);

I want to keep this interface, otherwise I can use the following code that used before :

mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID+1);

thank you in advance

edit retag flag offensive close merge delete

Comments

OpenCvCameraView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_FRONT);

CFeltch gravatar imageCFeltch ( 2015-03-08 21:47:25 -0600 )edit

5 answers

Sort by ยป oldest newest most voted
5

answered 2012-12-24 00:43:57 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Since OpenCV 2.4.3.1 you can define camera id using layout.xml. Simply add opencv:camera_id="value" attribute to rg.opencv.android.JavaCameraView or org.opencv.android.NativeCameraView. "any", "back", and "front" values are supported. In case if you have several cameras (more then 2), you can define camera by number. See example tutorial-1-addopencv from OpenCV SDK 2.4.3.1 for more details.

edit flag offensive delete link more
5

answered 2014-01-17 00:49:56 -0600

Naren gravatar image

Instead of modifying the source file you can also use the setCameraIndex() function in the CameraBridgeViewBase.

 mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.fd_activity_surface_view);
 mOpenCvCameraView.setCameraIndex(1);
 mOpenCvCameraView.setCvCameraViewListener(this);

Default camera index is -1. But before setting the front camera check whether front camera is available or not.

edit flag offensive delete link more
3

answered 2012-11-16 07:45:14 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

This is not implemented in the current version of OpenCV4Android application framework. You can submit a feature request to make sure we will not forget this feature.

Now you can either modify existing NativeCameraView (and submit a pull-request!) or use inheritance to alter its behavior.

edit flag offensive delete link more
1

answered 2012-11-18 15:00:57 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Thank you Andrey.

I resolved this issue modifying the NativeCameraView as you told me. This is a provisional solution, but it's easy and quick.

What I have done is to go to OpenCV Library - 2.4.3 eclipse project, them open org.opencv.android package. Them open file NativeCameraView and change the VIdeoCapture initialization on initializeCamera function.

mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID+1);

image description

After doing it, we can use the new OpenCV interface with NativeCameraView that inherits of CameraBridgeViewBase

NativeCameraView mOpenCvCameraView;
mOpenCvCameraView = (NativeCameraView)findViewById(R.id.activity_native_surface_view);   
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);   
mOpenCvCameraView.setCvCameraViewListener(this);
edit flag offensive delete link more

Comments

Please, submit a feature request for this (to code.opencv.org) and add link to this post in ticket.

Daniil Osokin gravatar imageDaniil Osokin ( 2012-11-19 02:15:34 -0600 )edit
0

answered 2012-12-22 01:02:20 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Does the problem solved ? What method be used to open the front camera ?

edit flag offensive delete link more

Comments

1) please don't use answer form for a comment or additional question

2) use the solution above described by Alexander Smorkalov

Andrey Pavlenko gravatar imageAndrey Pavlenko ( 2012-12-24 05:35:33 -0600 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-11-15 13:25:02 -0600

Seen: 17,565 times

Last updated: Jan 17 '14