Closed onuralpszr closed 3 years ago
That looks like related with this issue : https://github.com/bazelbuild/bazel/issues/12702
I managed to compile with this change in WORKSPACE
http_archive(
name = "com_google_absl",
urls = [
"https://github.com/abseil/abseil-cpp/archive/20210324.0.tar.gz",
],
# Remove after https://github.com/abseil/abseil-cpp/issues/326 is solved.
patches = [
"@//third_party:com_google_absl_f863b622fe13612433fdf43f76547d5edda0c93001.diff"
],
patch_args = [
"-p1",
],
strip_prefix = "abseil-cpp-20210324.0",
sha256 = "dd7db6815204c2a62a2160e32c55e97113b0a0178b2f090d6bab5ce36111db4b"
)
But didn't tested yet. (I'll update the comment when I tested)
I was able to use Kotlin with basic face detection :+1: the only issue I had "camera" didn't start normal but start with "black screen" until rotate landmark then portrait mode.
import android.graphics.SurfaceTexture
import android.os.Bundle
import android.util.Log
import android.util.Size
import android.view.SurfaceHolder
import android.view.SurfaceView
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.google.mediapipe.components.CameraHelper.CameraFacing
import com.google.mediapipe.components.CameraXPreviewHelper
import com.google.mediapipe.components.ExternalTextureConverter
import com.google.mediapipe.components.FrameProcessor
import com.google.mediapipe.components.PermissionHelper
import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmarkList
import com.google.mediapipe.framework.AndroidAssetUtil
import com.google.mediapipe.framework.Packet
import com.google.mediapipe.framework.PacketGetter
import com.google.mediapipe.glutil.EglManager
import com.google.mediapipe.framework.AndroidPacketCreator
class MainActivity : AppCompatActivity() {
private val BINARY_GRAPH_NAME = "face_detection_mobile_gpu.binarypb"
private val INPUT_VIDEO_STREAM_NAME = "input_video"
private val OUTPUT_VIDEO_STREAM_NAME = "output_video"
private val CAMERA_FACING = CameraFacing.FRONT
// Flips the camera-preview frames vertically before sending them into FrameProcessor to be
// processed in a MediaPipe graph, and flips the processed frames back when they are displayed.
// This is needed because OpenGL represents images assuming the image origin is at the
// bottom-left corner, whereas MediaPipe in general assumes the image origin is at top-left.
private val FLIP_FRAMES_VERTICALLY = true
companion object {
// Used to load the 'native-lib' library on application startup.
init {
System.loadLibrary("mediapipe_jni")
System.loadLibrary("opencv_java3")
}
}
// {@link SurfaceTexture} where the camera-preview frames can be accessed.
private var previewFrameTexture: SurfaceTexture? = null
// {@link SurfaceView} that displays the camera-preview frames processed by a MediaPipe graph.
private var previewDisplayView: SurfaceView? = null
// Creates and manages an {@link EGLContext}.
private var eglManager: EglManager? = null
// Sends camera-preview frames into a MediaPipe graph for processing, and displays the processed
// frames onto a {@link Surface}.
private var processor: FrameProcessor? = null
// Converts the GL_TEXTURE_EXTERNAL_OES texture from Android camera into a regular texture to be
// consumed by {@link FrameProcessor} and the underlying MediaPipe graph.
private var converter: ExternalTextureConverter? = null
// Handles camera access via the {@link CameraX} Jetpack support library.
private var cameraHelper: CameraXPreviewHelper? = null
// Face mesh
private val INPUT_NUM_FACES_SIDE_PACKET_NAME = "num_faces"
private val OUTPUT_LANDMARKS_STREAM_NAME = "multi_face_landmarks"
// Max number of faces to detect/process.
private val NUM_FACES = 1
private val TAG = "LLOG"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//findViewById<TextView>(R.id.sample_text).text = stringFromJNI()
previewDisplayView = SurfaceView(this)
setupPreviewDisplayView()
// Initialize asset manager so that MediaPipe native libraries can access the app assets, e.g.,
// binary graphs.
// Initialize asset manager so that MediaPipe native libraries can access the app assets, e.g.,
// binary graphs.
AndroidAssetUtil.initializeNativeAssetManager(this)
eglManager = EglManager(null)
processor = FrameProcessor(
this,
eglManager!!.nativeContext,
BINARY_GRAPH_NAME,
INPUT_VIDEO_STREAM_NAME,
OUTPUT_VIDEO_STREAM_NAME
)
processor!!.videoSurfaceOutput.setFlipY(FLIP_FRAMES_VERTICALLY)
PermissionHelper.checkAndRequestCameraPermissions(this)
val packetCreator:AndroidPacketCreator = processor!!.packetCreator
val inputSidePackets: MutableMap<String, Packet> = HashMap()
inputSidePackets[INPUT_NUM_FACES_SIDE_PACKET_NAME] = packetCreator.createInt32(NUM_FACES)
processor!!.setInputSidePackets(inputSidePackets)
//logFaceLandmark()
}
override fun onResume() {
super.onResume()
converter = ExternalTextureConverter(eglManager!!.context)
converter?.setFlipY(FLIP_FRAMES_VERTICALLY)
converter?.setConsumer(processor)
if (PermissionHelper.cameraPermissionsGranted(this)) {
startCamera()
}
}
override fun onPause() {
super.onPause()
converter!!.close()
}
private fun startCamera() {
cameraHelper = CameraXPreviewHelper()
cameraHelper!!.setOnCameraStartedListener { surfaceTexture: SurfaceTexture? ->
previewFrameTexture = surfaceTexture
// Make the display view visible to start showing the preview. This triggers the
// SurfaceHolder.Callback added to (the holder of) previewDisplayView.
previewDisplayView!!.visibility = View.VISIBLE
}
cameraHelper!!.startCamera(this, CAMERA_FACING, /*surfaceTexture=*/null)
}
private fun setupPreviewDisplayView() {
previewDisplayView!!.visibility = View.GONE
val viewGroup = findViewById<ViewGroup>(R.id.preview_display_layout)
viewGroup.addView(previewDisplayView)
previewDisplayView!!
.holder
.addCallback(
object : SurfaceHolder.Callback {
override fun surfaceCreated(holder: SurfaceHolder) {
processor!!.videoSurfaceOutput.setSurface(holder.surface)
}
override fun surfaceChanged(
holder: SurfaceHolder,
format: Int,
width: Int,
height: Int
) {
// (Re-)Compute the ideal size of the camera-preview display (the area that the
// camera-preview frames get rendered onto, potentially with scaling and rotation)
// based on the size of the SurfaceView that contains the display.
val viewSize = Size(width, height)
val displaySize: Size =
cameraHelper!!.computeDisplaySizeFromViewSize(viewSize)
// Connect the converter to the camera-preview frames as its input (via
// previewFrameTexture), and configure the output width and height as the computed
// display size.
converter?.setSurfaceTextureAndAttachToGLContext(
previewFrameTexture, displaySize.height, displaySize.width
)
}
override fun surfaceDestroyed(holder: SurfaceHolder) {
processor!!.videoSurfaceOutput.setSurface(null)
}
})
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
}
I had to also change setSurfaceTextureAndAttachToGLContext
width = displaySize.height height = displaySize.width
Because there was a "stretched in width" I don't know because of layout but It was ugly.
converter?.setSurfaceTextureAndAttachToGLContext(
previewFrameTexture, displaySize.height, displaySize.width
)
Hello, is there any updates about this ?
Thank you :)
Hi @thunderbirdtr, Let us know if you still are looking resolution for the above query. We also have a latest update that we released Face detection Android gradle API in our github repo. Try checking it and let us know if that works. Thanks!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.
Hi @thunderbirdtr, Let us know if you still are looking resolution for the above query. We also have a latest update that we released Face detection Android gradle API in our github repo. Try checking it and let us know if that works. Thanks!
Thank you for updates, I'll try and get back to you asap. Let me do clean test as well.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.
Hello, I was trying to build AAR file for learning/my project so I followed this link and it failed and has error
https://google.github.io/mediapipe/getting_started/android_archive_library.html
I checked other issues saw protobuf patches but already in there (0.8.3-2) then I looked for that other issues but didn't see something similar.
bazelisk build -c opt --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --fat_apk_cpu=arm64-v8a,armeabi-v7a --strip=ALWAYS mediapipe/examples/android/src/java/com/google/mediapipe/apps/facedetectioncpu_aar:mp_face_detectioncpu_aar