How to paste stuff over a camera preview on Android? - 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.

Related

Hide camera preview in OpenCV 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.

Universal screen resolutions in Unity for Android

I am new to Android development. I sent my app for testing on a couple of devices and a couple were fine, but a couple had the game half way off the screen. In the game scene everything is fine so what could be causing this in some devices?
I am using one main camera set to orthographic and it is a simple 2d game.
I guess one of my mistakes was not using the canvas properly and so I will make improvements, but why would this be like this in the game scene where I cannot use a canvas? Do I have to fix the position of main camera also?
Thankyou for help with this.
Try playing around with your canvas' screen match mode. I would try the expand or shrink option. This is pretty self explanatory, it will either shrink or expand your canvas to match the width or the height (depending on your settings for the canvas) of your display. If you're stuck, take a look at the doc for the canvas:
http://docs.unity3d.com/Manual/script-CanvasScaler.html
And the last thing is to play around with your UI elements' anchor positions. Here's the doc for the anchor positions:
http://docs.unity3d.com/Manual/UIBasicLayout.html
Hope this helps!

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!

GridView with images vs custom drawn Canvas for Android memory game

Say I'd like to make a memory/pairs game. I have currently made a draft that works on a Canvas, and cards are drawn into a grid.
This works for my current basic version, but I'd like show do an animation (when the card is turned, it will flip around and scale to higher size; or when the match is found, the cards would rotate around and then go back.
I can't imagine doing this on Canvas, I'd have to make a lot of timers and do the animation by hand, it seems overly complex for this simple task.
I think I could could subclass View for a control that would display a card, and then react to touch events for that control. It would also make drawing scaling of the images done by Android itself, and, most importantly, I could use Tween Animation for some effects.
My question is - would it be OK to use a View for each card in the game (I could have 5x6 or 4x5 cards), and arrange them in a GridView? Are there some pitfalls with this approach? Or should I continue with completely custom-drawn Canvas?
For such a simple game you should be fine using a collection of Views. As you mention using Views rather than trying to do it manually you get access to a lot of nice Animation functionality for free.
It also makes implement the user interface a lot simpler as you can just add onClickListeners to each view to capture user touches. If you're drawing it all manually to a Canvas then you'd have to interpret the touches yourself and decide which card was touched etc. While this isn't too hard, then I think subclassing View is a better model and will most likely result in cleaner code.
As you are only going to have 30 cards, then I can't imagine you having performance issues either - if you were thinking 100+, then maybe you'd have an issue, but I think you're fine. Also, if I understand your game correctly, the majority of your cards won't be animating most of the time so that's yet another reason not to worry - if you ever run into performance issues with the animations you can easily save off all the unanimated Views onto a Bitmap (Canvas) for the duration of the animation.

Android - How can I show camera in 2 or more views

I'm trying to create an Android app based on camera.
I want to split my screen into 2 or 4 views. (when 2 views are show, one will be above and one will be below. And when 4 views, 2 will be on top (side by side) and 2 will be at bottom (side by side))
I want to show the what camera is seeing in all the views.
I mean all the views must render according to camera.
Is it possible? HOw?
This is not practical AFAIK. The camera will draw to only one SurfaceView, not four. While you could try to make a mock SurfaceView that then passes the information to four separate SurfaceViews, your performance probably will be awful.
The only way I see this being possible is having setPreviewCallback() method take those frames, converting them to bitmaps or jpegs, and then drawing those images on the other surface views. I'm with CommonsWare though. It will be slow and painful.
I've actually did that in my app Face Costume:
Face Costume
What I did was use the camera preview buffer, convert it from YUV to RGB, and render it on an OpenGL texture. You don't have to choose OpenGL, you can also do it using the regular canvas method.
On dual core tablets it works well... haven't tested it on other hardware.

Categories

Resources