How do I capture what is displayed on my camera surface area? - android

I am using a standard Android camera/surface area. I am not using the full screen, and have implemented the preview surface area with a height of 200dp. However, when I save the photo, it is saved as if the preview/surface area is the full screen.
Is there a way for me to save to a jpeg exactly what is displayed on the preview/surface area?
Some context for the question, I am using the camera to capture the text of a street sign, so I only need a very small image.

In my OCR applications I capture preview, and then extract subimages for further processing based on position of ROI ( determined by some surface overlay ).
See android demo code ( demos/ ) :
http://sourceforge.net/projects/javaocr/
I'm not aware of interface allowing ti capture only subimage

Related

Limit detection area of MLKIT of barcode scanner

I am implementing a barcode scanner using MLKIT in my application (Kotlin). I need the barcode to be processed only when it is visible in a transparent rectangle in the center of the screen. as we see in the picture below.
PIC 1
Right now my App detects every barcode visible in the camera view as shown below. Is it possible to limit the detection area so the detection only reads from a rectangle in the middle of the screen?
Besides I would like to create a custom PreviewView for a barcode with cameraX, as shown in PIC 1. Thank you.
PIC 2
ML Kit doesn't support specifying interested area currently, so you have to either crop the preview image or filter out barcode results that not in the specified area. Similar question How do I make the camera focus only inside the rectangle and read the text inside the rectangle only in a flutter?

Does mirroring the (front) camera affect MLKit with CameraX?

You might consider this question a sequel to this other one I've recently asked. I have a custom device with a front camera that is mirrored by default and I would like it to always behave like it was flipped horizontally. Note that the end goal of my app is to perform face, barcode and facemask detection (the last one with a custom .tflite model), and I'm trying to understand if it's possible with the current state of CameraX and the quirks of the device I'm using.
For the preview, I can force PreviewView to use a TextureView by calling PreviewView#implementationMode = PreviewView.ImplementationMode.COMPATIBLE so I can just call PreviewView#setScaleX(-1) and it gets displayed like I want.
For taking pictures, I haven't tried yet but I know I can pass setReversedHorizontal(true) to the ImageCapture.OutputFileOptions used in the ImageCapture.Builder, so the image should be saved in reverse.
For image analysis I really don't know. If the input image is taken directly from the preview stream, then it should still be in its default state because PreviewView#setScaleX(-1) only flips the View on screen, right? So in my Analyzer's analyze() I would need to convert the ImageProxy#image to bitmap, then flip it and pass the result to InputImage.fromBitmap().
Is this everything I need? Is there a better way to do this?

how to attach overlay to detected object using android and OpenCV

I'm writing an android app using OpenCV for my masters that will be something like a game. The main goal is to a detect a car in selected area. The "prize" will be triggered randomly while detecting cars. When the user will hit the proper car I want to display a 3D object overlay on the screen and attach it to the middle of the car and keep it there so when the user will change the angle of his view on the car, the object will also be seen from diffrent angle.
at the moment I have EVERYTHING beside attaching the object. I've created detection, I'm drawing the 3D overlay, I've created functions that allow me to rotate the camera etc. BUT I do not have any clue how can I attach the overlay to the specific point. Cause I don't have this I have no point to recalculate the renderer to change the overlay perspective.
Please, I really need some help, even a small idea will be fine:
How can I attach the overlay to the specific in real world
(Sorry, I couldn't comment. Need at least 50 points to do that ... :P )
I assume your image of the car is coming from a camera feed and you are drawing 3d car in opengl. If so, then you can try this:
You set the pixel format of the opengl layer as RGBA_8888, so that you can set the background of the opengl camera as a transparent color.
You take a relative layout as layout of your activity.
first you add the opencv camera layout to it as full height and width.
then you add opengl layer as full height and width.
you get the position of the real car from opencv layer as pixel value or something you did.
then scale it to your opengl parameters so that you can draw it on the right spot.
it worked for me. hope it works for you too.

Android Camera custom zoom anywhere on the camera view

Is there a way, in which I can select a focus area on the camera preview by touch gesture and zoom into that specific area?
The short answer is: yes, you can.
If your camera supports video resolution higher than the preview area, zoom in can show more details. Often, it's not the case, and zoomed in picture will not look good.

Android camera preview with fixed bounding box

I want to take a picture of a rectangle shaped object. If the camera preview have a bounding rectangle i can take the picture by placing the object inside the bounding box. I need only that specified(inside the box) area of the image.Now I have developed a Camera App(Using Camera API Not INTENT) which can take pictures and store the pic like the inbuilt camera App.
How to draw a rectangle on the camera preview? and how to crop before saving?
I am using android 2.2
You have to add an camera overlay to achieve this. Take a look at the Samples at samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview. You can have your own layout over the preview area and add your graphic to it.
Check: http://android-er.blogspot.in/2010/12/add-overlay-on-camera-preview.html
and Android: Crop an Image after Taking it With Camera with a Fixed Aspect Ratio for more samples.

Categories

Resources