I am working on an AR application using ARCore and Sceneform. I want to add texture to face landmarks like nose, lips, face and eyes. I want to know how to create texture so that I can overlay it on Augmented Face mesh?
Texture.builder()
.setSource(this, R.drawable.makeupforlips)
.setUsage(Texture.Usage.COLOR)
.build()
.thenAccept(texture -> faceMeshTexture = texture);
addOnUpdateListener:
for (AugmentedFace face: faceList) {
if (!faceNodeMap.containsKey(face)) {
AugmentedFaceNode faceNode = new AugmentedFaceNode(face);
faceNode.setParent(scene);
// faceNode.setFaceRegionsRenderable(faceRegionsRenderable);
faceNode.setFaceMeshTexture(faceMeshTexture);
faceNodeMap.put(face, faceNode);
}
}
When you're building ARCore app with Augmented Faces functionality you need to use a canonical face mesh that was saved in .fbx, .obj, or .glTF file format. Import this canonical face into Autodesk Maya and using UV Texture Editor, create a UV-mapped texture that can be repainted in Adobe Photoshop or Pixelmator.
Related
I am pretty new to Camera2 API and currenty trying to implement a camera preview into my own car application on an Android head unit (Model YT9213AJ). The preview should show the image of the reverse camera.
I've tested the following code on a Samsung Tablet (SM-P610) and it shows the camera preview images as expected, from both, rear and front camera.
private void bindPreview(#NonNull ProcessCameraProvider cameraProvider) {
CameraSelector cameraSelector = new CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_FRONT)
.build();
CameraManager manager = (CameraManager) context.getSystemService(CAMERA_SERVICE);
Size previewSize = getPreviewSize(manager.getCameraCharacteristics("1"));
Preview preview = new Preview.Builder()
.setTargetResolution(previewSize)
.setDefaultResolution(previewSize)
.setMaxResolution(previewSize)
.setTargetRotation(Surface.ROTATION_270)
.build();
preview.setSurfaceProvider(previewView.getSurfaceProvider());
Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner)this, cameraSelector, preview);
}
With this function to get the preview size:
Size getPreviewSize(CameraCharacteristics characteristics) {
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
Size[] previewSizes = map.getOutputSizes(SurfaceTexture.class);
return previewSizes[0]; // for the camera just one resolution is given, so this should be sufficient
}
This is what the image looks like, if I run it on the car head unit:
Example image preview from car head unit
(Sorry, can't embed images into post yet)
I've also run the App "Camera2 API probe", please find the results here on AirBeat. The camera with ID 5 seems to be an placeholder, I assume that the other two cameras (ID 0 and ID 1) are the representations of the two hardware inputs into the head unit.
Do you have any clue how I can correctly decode the image for this camera model? Thanks for your time.
You could try seeing if not rotating the output helps - the size listed by the camera is already portrait aspect ratio.
In general, though, it looks like whoever made this head unit didn't take a lot of care in making sure the camera output works with the display side, I'm guessing. So it may not be possible to get it to work with the CameraX PreviewView as-is. The PreviewView tries to select the best kind of output View for the API level that the device is, but it may be picking a path the manufacturer didn't actually test with. There's no built-in way to have it select the other option (SurfaceView or TextureView are the choices), so you'd have to modify PreviewView code or build your own Preview surface provider.
There's also no guarantee that'll help, depending on exactly how badly this device implements things.
Normally in openlayer, if I want to add an image I just create the layer and add it to the map by doing the following:
var map = new OpenLayers.Map(mapCanvas, mapOptions);
var layer = new ImageLayer().add(name, url, envelope, size, this.map);
with this function i can specify the envelope (norteast , northwest, southeast, southwest boundaries) with WGS84. I can also say the size of the image.
Is there anything similar in android studio for GMAPS? Thanks.
as advised by Antonio in the comment, Ground Overlays should do the trick.
What i'm trying to do:
Pull an image from sd-card on phone using Java Plugin.
Unity passes a texture ID to plugin.
Plugin uses opengl to assign the image to the texture in Unity through the ID.
Will (eventually) be used to play a video clip from the phone in Unity, for now, it's just trying to change a texture outside of unity.
My issue:
When i call the method in the plugin, passing texture.GetNativeTextureID() into it, the texture does not change. I'm currently only using a simple black 50x50 texture for testing, and the original texture is a flat white.
I'm worried that i've missed something significant, as this is my first time working with Gl calls in java. Much of the answers to similar problems involve using native C++ instead of Java, but I can't find a concrete answer saying that C++ must be used. I'd like to do my best to avoid writing another set of plugins and plugin handlers for C++, but if it's the most efficient/only way to get this working, i'll do it as i'm not unfamiliar with OpenGL and C++
Code:
The plugin method is called from OnPreRender() in a script attached to the main camera:
if (grabTex) {
int texPtr = m_VideoTex.GetNativeTextureID();
Debug.Log( "texPtr = " + texPtr );
m_JVInterface.SetTex( texPtr );
}
m_VideoTex is a basic Texture2D( 50, 50 ) with all pixels set to white, attached to the diffuse shader on the quad in the scene.
The Java plugin code is as follows:
public void SetTexture(Context cont, int _texPointer) {
if (_texPointer != 0) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inJustDecodeBounds = false;
final Bitmap bitmap = BitmapFactory.decodeFile("/storage/emulated/0/Pictures/black.jpg", options);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, _texPointer);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
Log.i("VideoHandler", "Recieved ID: " + _texPointer);
bitmap.recycle();
}
}
This is most likely a problem with the OpenGL Context. The easiest way would be to send the texture as raw bytes to Unity and then upload as texture inside Unity.
I have a mesh generated from data in Renderables. Environment is set. Material is a simple new Material().
... /*init renderable*/
/*set mesh parameters*/
renderable.mesh = new Mesh(false,
(int)(meshVertexArray.length/SurfaceBuilder.__ELEMENTSPERVERTEX__), /*!vertices, not cordinates*/
meshIndexArray.length,
new VertexAttribute(Usage.Position,3,"a_position"),
new VertexAttribute(Usage.Normal,3,"a_normal"),
new VertexAttribute(Usage.TextureCoordinates,2,"a_texCoords"),
new VertexAttribute(Usage.ColorPacked,4, "a_color")
);
... /*set vertices*/
The mesh is generated properly, but I can't see the textures, only the gray (shaded) triangles. I did try the rtfm method, but so far I saw no way to bind a texture, so it displays properly in libGDX, only with shaders, and I'm not using them (I'm catching up on them after this feature is implemented). Is there a way in libGDX to bind textures to a mesh without shaders?
Without seeing your texturing code, maybe try specify a texture for your material using the following format:
Material mat = new Material();
//set the diffuse channel on the texture using some texture
mat.set(TextureAttribute.createDiffuse(new Texture("crate.jpg")));
I'm having an issue with libgdx skin.
When the app is paused or goes into the background and then reopens all my scene2d textures are just showing up black. I assume that the underlying textures need to be reloaded.
I'm creating my skin using the following code
FileHandle jsonFile = Gdx.files.internal( "ui/uiskin.json" );
FileHandle atlasFile = Gdx.files.internal( "ui/uiskin.atlas" );
TextureAtlas atlas = new TextureAtlas(atlasFile);
skin = new Skin(jsonFile, atlas);
My question is if there any way that I can detect when the texture needs to be reloaded and how to best do this?
I have found that it is best to rebuild the skin when you reopen your app.