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

I want to image process android front camera frames inside a service.
I use OpenCV and therefore using CameraBridgeViewBase which asks for camera view.
I dont want to record the video. i need to process each frame in real time.
any solution ?

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.

Related

SurfaceView or TextureView which is better for Preview

Got stuck In a situation, where working on a Camera app for android. The Camera should be customized and
Customized Camera
and not just the built-in. That's fine. I want camera to detect the eyes, while capturing the photo.
But I have few questions:
What to do for preview of a camera
Whether to use TextureView or SurfaceView
After capturing the image, where should it be shown
What is openCV, if I work with Texture- or SurfaceView do I still need openCV
You can start with one of many tutorials, or pick up some boilerplate from GitHub. There is no big difference whether to use TextureView or SurfaceView. You don't need OpenCV unless you need some real time image processing. It is your free choice whether to show captured picture, where and when.
OpenCV is a library that provides implementations of various features, like face detection, image processing etc.
If you plan to use OpenCV, then it provides its own implementation of CameraView that can be used for the CameraPreview.
OpenCV should be used as its methods are rigorous and efficient.
you may want to refer this for your project
https://github.com/hosek/eyeTrackSample

Android taking images without preview using new "Camera2" api

I am new to Android, i want to take pictures in background without surface view/preview. I have searched online but the methods don't seem working for me. I want to use the latest Camera2 API.
Regards!
Muhammad Awais
Just create an ImageReader, and a camera capture session with that ImageReader's Surface. No need to have a SurfaceView or TextureView as well.
You'll need to stream some number of captures before starting to save any, though, to ensure that the auto-exposure/focus/etc routines of the camera have time to converge.

Android SDK 4.0 Reading Camera Preview Frames only in a Service without Activity

I'm working on a computer-vision application that uses rear camera.
I'm using Android SDK for 4.0 (API 14)
I spent a few days trying to get preview frame in realtime, through onPreviewFrame, but have failed so far.
I think that the camera actually invoke preview callback when the previewDisplay is actually rendered in an activity.
But I have to capture camera images only in a service, without activity.
Any suggestions for this?
I've already tried making dummy surfaceView but it won't work.
I suggest trying Service.startActivity(intent)
Services don't have a UI, you need an Activity for that. But you can start an Activity from your Service.
Also, I don't think you can take a picture without the user's knowledge.

android camera working after minimizing

As you may notice, camera in android phones stops working when we minimize it (for example when we start a new application). My question is: Is there any way to create an app with android camera, which records even if we minimize it so it could be recording videos while we are doing something different on our phone? Or may be it is only possible if we create such camera without using MediaStore? If you share some links or code which might help me, I'll be grateful. Thanks in advance.
I believe the answer to this is that one must use
public final void setPreviewTexture (SurfaceTexture surfaceTexture)
Added in API level 11
Sets the SurfaceTexture to be used for live preview.
Either a surface or surface texture is necessary for preview,
and preview is necessary to take pictures.
from https://developer.android.com/reference/android/hardware/Camera.html . And
from https://developer.android.com/reference/android/graphics/SurfaceTexture.html :
The image stream may come from either camera preview or video decode.
A SurfaceTexture may be used in place of a SurfaceHolder when specifying the
output destination of a Camera or MediaPlayer object. Doing so will cause all the
frames from the image stream to be sent to the SurfaceTexture object rather than
to the device's display.
and I would really like to try this and send you some code, but I have no phone more recent than gingerbread, and this was introduced with honeycomb.
Using a surface associated with an Activity, surfaceDestroyed is called sometime between onPause and onStop when the Activity is being minimised, although, oddly, not when the phone is being put to sleep: How SurfaceHolder callbacks are related to Activity lifecycle? But I hope that a surfaceTexture is not destroyed in this way.

Running 2 instances of the Camera at the same time

I was wondering whether it is possible to have 2 instances of the camera preview in android. What I mean is running 2 instances of the camera at the same time. If it is, how would one go about this, will there be need to implement an instance on a different thread? I have not used the camera API before, so I would appreciate it if I can have a heads up on the issue, so I don't waste time on it.
Thank you.
It is not possible to have two open connections to the camera - you have to lock the camera in order to get a preview and it can only be locked once. Indeed, if you have the camera locked, and your app crashes before you've unlocked it, then nobody can use the camera!
See http://developer.android.com/reference/android/hardware/Camera.html#open%28int%29
You must call release() when you are
done using the camera, otherwise it
will remain locked and be unavailable
to other applications.
...
RuntimeException: if connection to the
camera service fails (for example, if
the camera is in use by another
process).
That said, you can certainly register a preview callback and take the preview data from your single camera instance to use in multiple views. But be aware of the issues with the YUV format of the raw byte[] data provided by the preview callback: Getting frames from Video Image in Android (note that the preview data is raw from the camera driver and may vary from device to device)
Ignoring the big Why question, your best bet would be to make a service that interacts with the camera, and go from there.

Categories

Resources