玩瞳文档中心


相机接口

<h3>概述</h3> <p>该部分接口的入口类为 <strong>VTBRSDKManager</strong>,在调用该部分接口前,需要打开sdk和license认证通过,否则有可能会导致部分功能无法正常work。</p> <h3>1. 打开相机</h3> <p><strong>接口名称:</strong></p> <pre><code class="language-java">public void openCamera()</code></pre> <p><strong>备注:</strong></p> <p>在开启识别前必须调用此接口打开相机,并确保<strong>拥有相机权限</strong></p> <h3>2. 关闭相机</h3> <p><strong>接口名称:</strong></p> <pre><code class="language-java">public void closeCamera()</code></pre> <p><strong>备注:</strong></p> <p>退出app时(例如onPause回调中)可调用该接口关闭相机</p> <h3>3.自定义相机</h3> <p>用户可根据自己需要自定义相机功能,自定义相机功能需要做两步操作。 1、继承<strong>AbstractVTCameraCrtl</strong>类; 2、调用<strong>ICameraPreviewCallback</strong>接口对象调用<strong>previewCallback</strong>方法将相机数据传给sdk; <strong>备注:</strong> 自定义相机可以参照壳app中的<strong>VTCameraCtrl</strong>和<strong>VTCamera1</strong></p> <h5>3.1 AbstractVTCameraCrtl类介绍</h5> <p>AbstractVTCameraCrtl类是一个虚类,里面有两个方法openCamera和closeCamera;</p> <p><strong>方法名称:</strong></p> <pre><code class="language-java">public abstract void openCamera(int cameraId, int previewWidth, int previewHeight, ICameraPreviewCallback previewCallback); </code></pre> <p><strong>参数:</strong></p> <table> <thead> <tr> <th>参数名</th> <th>类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>cameraId</td> <td>Int</td> <td>摄像头id</td> </tr> <tr> <td>previewWidth</td> <td>Int</td> <td>预览图片宽度</td> </tr> <tr> <td>previewHeight</td> <td>Int</td> <td>预览图片高度</td> </tr> <tr> <td>previewCallback</td> <td>ICameraPreviewCallback</td> <td>预览回调接口</td> </tr> </tbody> </table> <p><strong>备注:</strong> <strong>camerId</strong>表示是要开启那个摄像头,<strong>previewCallback</strong>不用用户自己实现,固定传入<strong>VTRecognizeMgr</strong>对象。</p> <p><strong>方法名称:</strong></p> <pre><code class="language-java">public abstract void closeCamera();</code></pre> <p><strong>备注:</strong></p> <p>该方法中主要做camera的关闭释放操作。</p> <p><strong>方法名称:</strong></p> <pre><code class="language-java">public abstract int getCustomPreviewWidth(); public abstract int getCustomPreviewHeight();</code></pre> <p><strong>备注:</strong> (已经废弃 传0就好) 该方法用于SDK获取壳程序的自定义预览分辨率。</p> <h4>3.2 ICameraPreviewCallback介绍</h4> <p>ICameraPreviewCallback是AbstractVTCameraCrtl类的一个内部接口,里面只有一个方法onPreview;</p> <p><strong>方法名称:</strong></p> <pre><code class="language-java">/** * 预览回调 * * @param data NV21格式的预览数据 */ void onPreview(byte[] data,int width ,int height);</code></pre> <p><strong>参数:</strong></p> <table> <thead> <tr> <th>参数名</th> <th>类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>data</td> <td>byte数组</td> <td>图像数据</td> </tr> <tr> <td>width</td> <td>int</td> <td>预览图像宽</td> </tr> <tr> <td>height</td> <td>int</td> <td>预览图像高</td> </tr> </tbody> </table> <p><strong>备注:</strong> 自定义Camera中需要用户在获取相机<strong>原始数据</strong>后通过调用<strong>previewCallback.onPreview()</strong>方法将此数据回传给sdk。注意:<strong>此操作必须执行,否则SDK将不会执行后续的识别功能</strong>。</p>

页面列表

ITEM_HTML