Ask Your Question
4

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

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 reopen merge delete

Closed for the following reason question is not relevant or outdated by berak
close date 2019-10-13 00:49:19.521172

Comments

OpenCvCameraView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_FRONT);

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

6 answers

Sort by » oldest newest most voted
6

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
6

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
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 2019-10-12 20:33:18 -0600

wade wang gravatar image

In my case, i just add cameraBridgeViewBase.setCameraIndex(1);in the protected void onCreate(Bundle savedInstanceState) {...}, and it works !

edit flag offensive delete link more

Comments

I found a simple way to use the a web cam (IP Webcam installed on my smartphone through Play Store) as camera using OpenCV and Java. Here is how: just copy the IP Webcam web link inside the Video Capture. Like this.

org.opencv.videoio.VideoCapture webSource = new VideoCapture("http://192.168.43.1:8080/video");

The smartphone and the laptop should be inside the same Wi-Fi.

Nouhoum Ibrahim Traoré gravatar imageNouhoum Ibrahim Traoré ( 2020-02-25 21:13:30 -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

Question Tools

Stats

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

Seen: 24,555 times

Last updated: Oct 12 '19