首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从移动视觉的人脸跟踪摄像机获取位图

从移动视觉的人脸跟踪摄像机获取位图
EN

Stack Overflow用户
提问于 2016-12-07 16:45:53
回答 1查看 808关注 0票数 1

我正试图从移动视觉的面部跟踪相机获得一个位图,但经过大约5个小时的尝试,我有点卡住了。

一.第一,结果:空白图像

代码语言:javascript
复制
Bitmap image = mSurfaceView.getDrawingCache(). 

我已经在这里为SetDrawingCache设置了真:

代码语言:javascript
复制
    public CameraSourcePreview(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;
    mStartRequested = false;
    mSurfaceAvailable = false;
    mSurfaceView = new SurfaceView(context);
    mSurfaceView.getHolder().addCallback(new SurfaceCallback());

    //HERE
    mSurfaceView.setDrawingCacheEnabled(true);

    addView(mSurfaceView);
    }

在那之后,我试着:拍摄图片OVerlay的截图,并从相机中获得一个截图,然后合并这两个位图->结果:可怕。一切都必须是对的是错的。

如果有人能想出任何解决方案(甚至建议都可以),我将非常感激。

泉。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-08 03:10:00

经过8个小时的尝试。我能解决这个问题。

首先,我得到了覆盖屏幕截图与它的X和Y在脸跟踪相机:

代码语言:javascript
复制
overlay = screenShot(mGraphicOverlay);
final float overlayX = mGraphicOverlay.getX();
final float overlayY =  mGraphicOverlay.getY();

然后我从相机里拍了张照片。调整覆盖层的大小,以适应相机的图片。在此之后,我将这2合并成1位图。然后把它送回主要活动。

代码语言:javascript
复制
 mCameraSource.takePicture(null, new CameraSource.PictureCallback(){
                @Override
                public void onPictureTaken(byte[] bytes) {
                    //Bitmap loadedImage = null;
                    loaded = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

                    Bitmap rotatedBitmap = null;
                    Matrix rotateMatrix = new Matrix();
                    rotateMatrix.postRotate(90);
                    rotatedBitmap = Bitmap.createBitmap(loaded, 0, 0,
                            loaded.getWidth(), loaded.getHeight(),
                            rotateMatrix, false);

                    overlay = resize(overlay,rotatedBitmap.getWidth(), rotatedBitmap.getHeight());


                    merged = MergeBitmap(rotatedBitmap, overlay, overlayX, overlayY);

                    Intent myIntentA1A2 = new Intent(context, MainActivity.class);

                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    merged.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
                    byte[] byteArray = byteArrayOutputStream .toByteArray();
                    String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
                    //imgDecodableString = BitMapToString(GlobalResource.glass);
                    myIntentA1A2.putExtra("Image", encoded);

                    context.startActivity(myIntentA1A2);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41022931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档