Hide camera preview in OpenCV android - android

I am building this application where I need to get video with the camera and process it with openCV as well as show a view with 3D graphics being renderered in it.I am using two fragments. One for previewing the camera. And one for the 3D graphics.The problem is the 3d graphics view has to be fullscreen. I don't want the camera preview at all. I can show them side by side using linear layout. But I cannot totally hide the preview and make the 3d scene take up the whole screen. Even using relative layout causes the camera preview to tear through the 3d graphics view.
Simply put it, if the camera preview is not being shown, the CvCameraViewListener2.onCameraFrame() method is not called. And without that I don't receive any new frames to process.

The problem got solved. I really don't know how it got solved though. I woke up the next day and tried running the project and it ran perfectly without requiring to change anything.

Related

Cannot perform animations of a view which is on top of a SurfaceView

Previously, I've been developed a library to facilitates the usage of Camera API: The Camerakit. I'm recently developing a new project with this library and I want to perform animations on the top of camera preview(which extends SurfaceView),I found when I added such as the following code to my application, the animations of the view is not performed properly with camera preview, but performed well when without camera preview.
// MainActivity.class
capture.animate().yBy(2000).setDuration(10000).start();
Is there a way to solve this problem?
I got this problem when i code android with Unity.Then I solved this problem by setting SurfaceView's level on the Z axis direction. As we all know,SurfaceView is a view which drew above the shell.Maybe you can got the SurfaceView's instance,then set it under the view.like this:((SurfaceView)child).setZOrderOnTop(false);
So,in fact,the animation has already run.It just be covered by SurfaceView.
Playing around with animating camera controls over a custom camera activity and I too ran into this problem. My camera controls would get cut off at an almost random point in their animation over the camera view. After playing around for a few hours as well as trying out Z ordering, the thing that worked for me was adding a full size child view with a background color (transparent works fine!). Not sure if the ordering of the view matters (I placed it right before/above the view I wanted to animate).
I finally figured it out. By changing the preview component which is SurfaceView to TextureView solve this issue. Now I can overlay any animation on my camera preview.
I also updated my code on Github.
This commit reproduces the issue. And this one solved it.
if you have to use surfaceview, there is a solution, put a no-TRANSPARENT view between surfaceview and your target view.

UI/Canvas appears in front of objects, even though it's set to World Space

In my Google Cardboard project, I have several canvases attached to walls in a room. These canvases have buttons the player can interact with. I set each canvas to World Space, but for some reason, the buttons are rendering in front of objects that should appear in front of the buttons.
update1:
The UI appears behind the cube in the game and scene windows when not running. It's only when I hit play that the image appears in front of the cube. I am adding images to the UI button programatically, but the problem happens even if I add images only using the editor.
update2:
If I disable the cardboard elements in my scene (i.e. use a standard fps camera setup), I do not get the issue.
Picture below: Checkerboard is UI. Gray block is 3D block. I want UI behind the block, on the wall.
Manually move the parent UI object behind the gray object.
Someone on answers.unity3D made this suggestions:
The problem may come from the shader used by the UI element with a
ZTest value set to Off or the Queue tag of the UI element's shader is
"higher" than the tag of the cube's shader
Turns out, and this is apparent in the 3rd screenshot, my UI buttons did not have a material. Once I provided one, I used one that used a standard UI shader (I initially tried unlit, but that made them disappear).
I guess there are still some issues with shaders and google cardboard. Thanks guys

Overlaying images over camera. Augmented reality

So, I'm trying to create a Augmented reality app on android (client/server).
My question is if i can overlay images and text boxes over the camera in real time or only if i have the capture to display it on the screen and add the extra information
If the first version can be implemented can someone help me with some starting code or links with suggestions
I did something similar for one of my apps,
And the way i did it is by placing an empty View on top of camera surfaceView using FrameLayout, then used onDraw method in the View class, to play with canvas and put anything i wanted on top of the camera view, you can practically do everything with Canvas, and since literally your view is overlaying the camera surfaceView, will do exactly the trick you are trying to accomplish here...
Regards!

Android: onPreviewFrame never called without SurfaceView

On some devices, onPreviewFrame is not called if no SurfaceView was set to display the camera preview.
However, I handle the camera in a service, so I can't set a SurfaceView but I don't want to have visible preview anyway.
How can this be done? Can I programmatically create a SurfaceView and set it with Camera::setPreviewDisplay?
This must be possible or not?
It works on almost every phone without a SurfaceView but not on HTC One X and Google Nexus One...
According to this question, creating a SurfaceView in code works fine. Though I don't think you can create it through a service.
Another approach is to create a 1px-1px SurfaceView inside a RelativeLayout and hiding it with some other view on top of it. (visibility should still be VISIBLE). We use this trick for Path camera UI where we render preview buffers through OpenGL and it works fine.
According to documentation readily configured, visible and displayed surface view is necessary to activate camera preview. It may be overlayued though
From API 11 on, you can use a SurfaceTexture instead of a SurfaceView to get frames from the camera. Then, instead of using Camera.setPreviewDisplay, simply use Camera.setPreviewTexture.
This answer as well as this one discuss this point.

How to paste stuff over a camera preview on Android?

I am making the classic AR app for Android.
I am using a SurfaceView to show the camera.
I want to know, how I put things over it... Currently I am using widgets, but they have two issues:
First, they are slow.
Second, you cannot rotate them in 1.5 without using view animation, and noone I asked so far (here, forums, google, irc...) knows how view animation work, so I am failing to make the view animation work in sync with the custom view that put widgets over the camera (resulting in flickering).
Thus I decided to change the method of putting things on the screen, so what other ways exist? (note I am bound to Android 1.5)
Seemly it cannot be done easily, but I could put a image and rotate it easily using Matrix.
I basically placed on layout over the preview a ImageView, then I used setMatrix to a rotation matrix, and voilá, I got a rotated image that works in 1.5
You must use OpenGL for drawing Objects over your SurfaceView.

Categories

Resources