目录

class info
com.huawei.hms.mlsdk.common.LensEngine
Represents a class with the camera initialization, frame obtaining, and logic control functions encapsulated.

Constant Summary

TypeNameDesc
intBACK_LENSRear camera.
intFRONT_LENSFront camera.

Public Method Summary

Return typeMethod name
voidclose()
intdoZoom(float scale)
SizegetDisplayDimension()
intgetLensType()
CameragetLens()
voidphotograph(LensEngine.ShutterListener shutterListener, LensEngine.PhotographListener photographListener)
voidrelease()
LensEnginerun()throws IOException
LensEnginerun(android.view.SurfaceHolder surfaceHolder)throws IOException
LensEnginerun(android.graphics.SurfaceTexture surfaceTexture)throws IOException

Constants

Constant
public static final int BACK_LENS
Rear camera.
Constant Value: 0。
Constant
public static final int FRONT_LENS
Front camera.
Constant Value: 1。

Public Methods

Method
public synchronized void close()
Closes the camera and stops sending frames to the frame analyzer.
Method
public synchronized int doZoom(float scale)
Adjusts the focal length of the camera based on the scaling coefficient (digital zoom).

Parameters

Parameter nameParameter desc
ScaleScaling coefficient.If the scaling coefficient is greater than 1.0, the focal length is calculated as follows: Maximum focal length supported by the camera x 1/10 x Scaling coefficientIf the scaling coefficient is 1.0, the focal length does not change.If the scaling coefficient is less than 1.0, the focal length equals the current focal length multiplied by the scaling coefficient.


Return

TypeDesc
intFocal length after adjustment. If the focal length after adjustment is greater than the maximum supported by the camera, the maximum supported by the camera is used.
Method
public Size getDisplayDimension()
Obtains the size of the preview image of a camera.

Return

TypeDesc
SizeSize of the preview image of a camera.
Method
public int getLensType()
Obtains the selected camera type.

Return

TypeDesc
intSelected camera type.0: rear-facing camera1: front-facing camera
Method
public Camera getLens()
Obtains the camera instance.

Return

TypeDesc
CameraCamera instance.
Method
public void photograph(LensEngine.ShutterListener shutterListener, LensEngine.PhotographListener photographListener)
Monitors photographing.

Parameters

Parameter nameParameter desc
shutterListenerCallback function called upon shutter touch.
photographListenerCallback function called upon image data obtaining.
Method
public synchronized void release()
Releases resources occupied by LensEngine.
Method
public synchronized LensEngine run() throws IOException
Starts the LensEngine. During startup, the LensEngine selects an appropriate camera based on the user’s requirements on the frame rate and preview image size, initializes parameters of the selected camera, and starts an analyzer thread to analyze and process frame data. If the Android SDK version is 11 or later, SurfaceTexture is used as the frame preview panel. Otherwise, SurfaceView is used as the frame preview panel. (A frame preview panel is used to preview images and display detection results.)

Return

TypeDesc
LensEngineCamera engine.


Throws

Exception nameException desc
IOExceptionThis exception is thrown if the LensEngine fails to start.
Method
public synchronized LensEngine run(android.view.SurfaceHolder surfaceHolder) throws IOException
Starts the LensEngine and uses SurfaceView as the frame preview panel.

Parameters

Parameter nameParameter desc
surfaceHolderFrame preview panel.


Return

Typedesc
LensEngineCamera engine.


Throws

Exception nameException desc
IOExceptionThis exception is thrown if the LensEngine fails to start.
Method
public synchronized LensEngine run(android.graphics.SurfaceTexture surfaceTexture) throws IOException
Starts the LensEngine and uses SurfaceTexture as the frame preview panel.

Parameters

Parameter nameParameter desc
surfaceTextureFrame preview panel.


Return

Typedesc
LensEngineCamera engine.


Throws

Exception nameException desc
IOExceptionThis exception is thrown if the LensEngine fails to start.