机器人 - 使用相机而无需surfaceview或textureview [英] android - use camera without surfaceview or textureview

查看:502
本文介绍了机器人 - 使用相机而无需surfaceview或textureview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出是否有一种方法可以使用​​相机采取任何视频/图片没有定义surfaceview或textureview。我发现这个链接:使用Android摄像头没有表面视图

I have been trying to figure out if there is a way to use camera to take either video/pictures without defining surfaceview or textureview. I found this link: Use Android Camera without surface View

我用这一招用textureview我的关系平板电脑,但没有运气!此外, HTTP://handy$c$cworks.com/ P = 19 说,这种做法没有按科技工作的所有设备。

I used this trick with textureview on my nexus tablet but no luck! Also, http://handycodeworks.com/?p=19 says that this approach doesn't work on all the devices.

没有人有任何想法,如果有一种方法可以做到这一点呢?或者它只是一些东西,android的架构并不支持所有的图形用户界面必须具有在布局一些表面/纹理元素?那么唯一的选择就是刚刚操纵布局,它不是屏幕根据应用程序的要求上不可见。

Does anyone have any idea if there is a way to do it at all? or its just something which android framework doesn't support at all and the GUI has to have some surface/texture element in layout? Then the only option is to just manipulate the layout so its not visible on the screen as per the app requirements.

编辑1: 正如上面的链接 HTTP://handy$c$cworks.com/ P = 19 ,我想下面的code:

EDIT 1: As explained in the above link http://handycodeworks.com/?p=19, I tried the below code:

public class CameraCapture {

  // I pass the getApplicationContext() from the main activity.
  public void startCameraCapture(Context contx) {
    SurfaceView sv = new SurfaceView(contx);
    mCamera = Camera.open();
    mCamera.setPreviewDisplay(sv.getHolder());
    mCamera.setPreviewCallback(new PreviewCallback() {
      @Override
      public void onPreviewFrame(byte[] data, Camera camera) {
        Log.v("TAG", "on preview frame called");
      }
    Thread.sleep(1000);
    mCamera.startPreview();
}

不过,在previewFrame()永远不会调用。我失去了一些东西?

However, onPreviewFrame() never invoked. Am I missing something?

编辑2:

是否有可能做本土code?捕捉视频/使用相机而无需使用OpenCV的GUI元素(surfaceview / textureview)?我看了看这个链接:<一href="http://docs.opencv.org/trunk/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-static-initialization">http://docs.opencv.org/trunk/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-static-initialization.然而,他们也表现出了样品code,在主要布局xml文件中定义了一些摄像头视图元素。

Is it possible to do in native code? Capturing video/using camera without GUI element (surfaceview/textureview) using OpenCV? I looked at this link: http://docs.opencv.org/trunk/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-static-initialization. However, they also show the sample code with some camera view element defined in main layout xml file.

推荐答案

我能够定义对象表面纹理如下做到这一点:

I'm able to do it by defining SurfaceTexture object as below:

SurfaceTexture surfaceTexture = new SurfaceTexture(10);
<camera object>.setPreviewTexture(surfaceTexture);

在此,我不需要在应用程序中定义的GUI元素。

In this, I don't need to define a GUI element in the app.

这篇关于机器人 - 使用相机而无需surfaceview或textureview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆