OpenCV Library for Android (portrait camera) - android

I am developing android application with facial recogniton using opencv library. My problem is the screen orientation. I got a solution with code below in JavaCameraView class.
mCamera.setDisplayOrientation(90);
mCamera.setPreviewDisplay(getHolder());
The camera is good but the facial detection doesnt work.
I found this but I think that the solution does not work in latest version of opencv library.
Any ideas could be useful.
Thanks in advance.

You have to also create the setDisplayOrientation by adding this:
protected void setDisplayOrientation(Camera camera, int angle){
Method downPolymorphic;
try
{
downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });
if (downPolymorphic != null)
downPolymorphic.invoke(camera, new Object[] { angle });
}
catch (Exception e1)
{
}
}

Related

Tokbox video publish unfocused (Android)

I am using tokbox for video chat and I want to take pictures of printed documents. When I am trying this on a Samsung s7edge my captured image is so unfocused I cannot read it. When I am trying this on a Nexus 6p the image is fine.
It is not a resolution problem, I am always using CameraCaptureResolution.HIGH
any thoughts?
I fixed it:
I used this class:
https://github.com/opentok/opentok-android-sdk-samples/blob/master/Custom-Video-Driver/app/src/main/java/com/tokbox/android/tutorials/customvideodriver/CustomVideoCapturer.java
Changed the init function:
#Override
public void init() {
mCamera = Camera.open(mCameraIndex);
mCurrentDeviceInfo = new Camera.CameraInfo();
Camera.getCameraInfo(mCameraIndex, mCurrentDeviceInfo);
try{
//set camera to continually auto-focus
Camera.Parameters params = mCamera.getParameters();
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
mCamera.setParameters(params);
}catch (Exception e) {
e.printStackTrace();
}
}
and the swapCamera as well, so every time the back camera comes into play It must have autofocus.
And in my Activity, onConnected:
CustomVideoCapturer mCapturer = new CustomVideoCapturer(a) ;
mPublisher = new Publisher.Builder(this)
.capturer(mCapturer)
.resolution(Publisher.CameraCaptureResolution.HIGH).build();

Can an android.hardware.camera2.CaptureRequest be used with OpenCV?

I've worked on this for days now. I have an OpenCV/JavaCameraView-based project I am trying to integrate with an Android android.hardware.camera2.CaptureRequest object I use to control the camera's sensitivity to light.
The CameraBridgeViewBase.CvCameraViewListener2/JavaCameraView project works (I can see an image on the screen), and the CaptureRequest project works (see this, too), but combining the two technologies in a single project has proved a big problem.
Has anyone gotten these two technologies to work together? My goal is to have the camera under the control of the CaptureRequest (limited SENSOR_SENSITIVITY + SENSOR_EXPOSURE_TIME), but for the screen to show a streaming image filtered through an OpenCV shared library I've written.
To control the camera, I can use something like this:
mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
new CameraCaptureSession.StateCallback() {
#Override
public void onConfigured(#NonNull CameraCaptureSession cameraCaptureSession) {
// The camera is already closed
if (null == mCameraDevice) {
return;
}
long exposureTime = 66259688,frameDuration = 1000;
int sensitivity = 1512;
mCaptureSession = cameraCaptureSession;
try {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
setAutoFlash(mPreviewRequestBuilder);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, Long.valueOf(exposureTime));
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, Integer.valueOf(sensitivity));
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_FRAME_DURATION, Long.valueOf(frameDuration));
mPreviewRequest = mPreviewRequestBuilder.build();
mCaptureSession.setRepeatingRequest(mPreviewRequest,
mCaptureCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
}
To filter the image stream, I can use something like this:
public class MyCoolScanner extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
...
#Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
OpenCVNative.myCoolLibrary(mRgba.getNativeObjAddr(),mGray.getNativeObjAddr());
return mGray;
}
Thanks in advance.
Please find implementation of open CV with Android , it may help you .
Camera calibration With OpenCV
Camera calibration - opencv 2.3.1 android
https://groups.google.com/forum/#!topic/android-opencv/xXtUvdA1E4M
https://fossies.org/dox/opencv-3.2.0/CameraCalibrationActivity_8java_source.html
I believe OpenCV does not natively support use with android.camera2
The answer is no, OpenCV will not work with android.camera2, not without some kind of convoluted work around.

Get the scanned image of barcode using zxing barcode scanner?

I have successfully integrated zxing Barcode scanner with Phonegap+sencha touch app. Now i have to capture the image also during the scan and return it to the view.
Thanks in Advance.
With ZXing APIs, you can implement it yourself. About how to use Android camera, please refer to Android website. Here is the code for capturing images from preview callback, as well as how to use zxing to decode the image:
private Camera.PreviewCallback mPreviewCallback = new PreviewCallback() {
#Override
public void onPreviewFrame(byte[] data, Camera camera) {
// TODO Auto-generated method stub
if (mDialog.isShowing())
return;
LuminanceSource source = new PlanarYUVLuminanceSource(data, mWidth, mHeight, mLeft, mTop, mAreaWidth, mAreaHeight, false);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(
source));
Result result;
try {
result = mMultiFormatReader.decode(bitmap, null);
if (result != null) {
mDialog.setTitle("Result");
mDialog.setMessage(result.getText());
mDialog.show();
}
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
For more detailed information, you can read the article How to implement a simple barcode scan application on Android

Adding camera effects in android and save

I am working on a new android application.In my app i have to add show effects on image preview [like sepia,pinch, mirror, etc] and capture and save image in that particular effect.eg: I f user select pinch effect then he can capture and store the image with pinch effect.
I had read some faq's. But they are telling about some ndk's.But i don't have any idea about ndk's. Please help me friends.
You can set all these kind of effects with camera instance itself. Walk though the below code ...
Camera camera = null;
camera = Camera.open();
if (camera != null) {
try {
Camera.Parameters parameters = camera.getParameters();
// Set all kind of stuffs here..
parameters.setSceneMode(Camera.Parameters.FLASH_MODE_AUTO);
parameters.setColorEffect(Camera.Parameters.EFFECT_SEPIA);
camera.setParameters(parameters);
camera.setPreviewDisplay(surface_holder);
camera.startPreview();
} catch (IOException exception) {
camera.release();
camera = null;
}
}

Use Android Camera without surface View

I'm developing on android, i want to do somethings with camera (process pixels's values), but just in background, is it possible to do it without surface view? just use a buffer to read pixels's values and do processing.
thanks for every one can help me
As of API-Level 11 the SurfaceTexture was added. With it a SurfaceView is no longer needed. I tested the following code with my Samsung Galaxy S3 Neo.
mCamera = Camera.open();
try {
mCamera.setPreviewTexture(new SurfaceTexture(10));
} catch (IOException e1) {
Log.e(Version.APP_ID, e1.getMessage());
}
Parameters params = mCamera.getParameters();
params.setPreviewSize(640, 480);
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
params.setPictureFormat(ImageFormat.JPEG);
mCamera.setParameters(params);
mCamera.startPreview();
mCamera.takePicture(null, null, null, new PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
Log.i(Version.APP_ID, "picture-taken");
}
});
I've been looking for an answer to this for a while. I found it there, copied here for convenience.
http://handycodeworks.com/?p=19
Basically, let's just create a dummy SurfaceView (it works even inside a Service), and use it for Camera functions.
SurfaceView view = new SurfaceView(this);
c.setPreviewDisplay(view.getHolder());
c.startPreview();
c.takePicture(shutterCallback, rawPictureCallback, jpegPictureCallback);

Categories

Resources