i am a beginner on android.
My question is simple, i need to capture a video frame from my device but i need to capture just a part of the entire camera view. For example, if my camera view display my frame on the entire screen i need to cut half frame to display.
I did this with opencv through image processing (image cropping) but i wanna know if this is possible also specifing the layout parameters. I need know if this is possible because i working with a video frame not with simple image and i need to ease the entire processing.
Thank you for all advices.
Related
I have the video preview from the camera which I want to crop.
But the cropping window is changing frame by frame (size and position of the cropping window).
How could I achieve this on Android (flutter, kotlin, java, nativescript,.. doesn't matter) to be able to show the live cropping results in a view and also be able to save the result to file?
I don't want the code, I just don't know which libraries and api's to use (link too documentation) and how the concept should be solved for this problem.
How to crop the live video from camera frame by frame and preview and save to file?
I created (partially) what I want in Javascript, just to show what I mean. In Javascript I use a HTML Video-tag (this could get the feed from the Webcam) then I create a Canvas and can read each frame of the video-tag as data and select exactly what I want from frame to frame.
let a = 10;
processor.computeFrame = function computeFrame() {
let frame = ctx.getImageData(a,0, this.width*0.5 +a, this.height); // here I use a moving window from left to right for the crop
ctx2.drawImage(frame, 0, 0); // and draw it back to the view (second canvas)
a +=0.1; //move the window
};
How can I solve this in Android?
I don't expect a fully working code... if you have any good articles, tutorials or documentation where I should start to read to achieve this, it would be perfect!
Interesting article:
https://engineering.depop.com/android-square-video-cropping-59b5edd69bce
https://www.programmersought.com/article/3222812179/
If you just wanted to crop preview, you could use a TextureView and update its transform matrix to match your desired crop rectangle.
If all you need is an occasional screen grab at the same resolution as preview for saving, you could use TextureView.getBitmap to read the cropped view to a Bitmap, and then save it.
If you need a higher-resolution or higher-quality capture, you'll need a separate output from the camera. Options are either capturing JPEG, decoding it, cropping the resulting Bitmap, and re-encoding it (assuming you want to save a JPEG, anyway), or capturing uncompressed YUV, cropping it, and then converting it to a Bitmap.
The CameraX Android support library might save you a lot of time in setting up the high-quality path, though I think you still need to do the cropping yourself for the output of the ImageCapture use case.
I would like to do a vuforia android application including some image processing operations.
I can do what I want by showing processed current image in ImageView. But it is too slow. I have tried to resize current image but it is not good like showing image in GLSurfaceView.
So, I thought that if I do manipulation on current image then show it in GLSurfaceView, it will be faster.
I wonder that if it is possible. If so, how can I do this? Could someone help me about this problem? Thanks in advance.
I need to custom view with live camera. I want my screen is divided into 9 parts, per part is show camera preview as photo below.
You can attach only one SurfaceView to live stream, and you cannot apply different 'effects' to this live preview. You can use OpenGL to resolve both limitations. See examples at https://github.com/google/grafika/blob/master/src/com/android/grafika/TextureFromCameraActivity.java and https://github.com/Sveder/CardboardPassthrough/tree/master/OpenGL%20Version.
I want to take a picture with my app, but I want to run the camera inside a fragment in a frame. Is it possible to accomplish that?
Any help appreciated..
It is Possible to Write your Own Camera Module using SurfaceView see the Android Documentation
for Building a Camera App, Example
If you want to add a frame to the picture taken, you must post-process the captured image, whatever method you choose - be it via intent, or Camera.takePicture().
If you want the preview to appear inside a rectangular frame, you simply create an xml layout to your liking, frame included, and a surfaceView positioned where you need it.
If your frame has some curls or curves on the inside, your preview surface should be z-ordered under this frame (which will include transparent areas).
I need a little help with getting my camera to work right.
What I'm trying to do is have the user take a picture that will then be used in another activity as the view's background. It is important not to have any skewing, and ideally the image would fill the entire background with the highest resolution possible.
I've been having a heck of a time trying to get the outputted picture of my camera to be oriented properly and be the same aspect of the display. So I took some time to think of exactly what I needed to do, and I don't think I need the normal saved image at all.
What I came up with is that I need a surface view to display the preview, and an overlay for some text and a capture button. When the user "takes the picture" it should autofocus, and then I need to capture the preview (under the screen overlays) to a bitmap to use in the other activity.
*Should I extend a SurfaceView for my preview and add it to a XML layout that contains the overlays?
*How do I save the SurfaceView's image to a bitmap?
Thanks.
Matt,
One basic question ,and excuse my naivety, wouldnt it just be easier to use the built in camera to the Android through an Intent? It is doable, I've done it before.
Apparently, there is no good way to convert the image format of the preview frames to a jpeg, so I ended up selecting the size for the camera to take by going through each of the camera's supported resolutions and getting the closest match the the screen aspect with the highest resolution.
Because the camera.setRotation method doesn't seem to do anything, I just rotate the image 90 with a matrix before saving it to the card if I am in portrait mode.