OpenCV 2.4.3.1

org.opencv.android
Class CameraBridgeViewBase

java.lang.Object
  extended by SurfaceView
      extended by org.opencv.android.CameraBridgeViewBase
Direct Known Subclasses:
JavaCameraView, NativeCameraView

public abstract class CameraBridgeViewBase
extends SurfaceView

This is a basic class, implementing the interaction with Camera and OpenCV library. The main responsibility of it - is to control when camera can be enabled, process the frame, call external listener to make any adjustments to the frame and then draw the resulting frame to the screen. The clients shall implement CvCameraViewListener.


Nested Class Summary
static interface CameraBridgeViewBase.CvCameraViewListener
           
static interface CameraBridgeViewBase.ListItemAccessor
           
 
Field Summary
protected  int mCameraIndex
           
protected  boolean mEnabled
           
protected  FpsMeter mFpsMeter
           
protected  int mFrameHeight
           
protected  int mFrameWidth
           
protected  int mMaxHeight
           
protected  int mMaxWidth
           
protected  int mPreviewFormat
           
 
Constructor Summary
CameraBridgeViewBase(Context context, AttributeSet attrs)
           
CameraBridgeViewBase(Context context, int cameraId)
           
 
Method Summary
protected  void AllocateCache()
           
protected  Size calculateCameraFrameSize(java.util.List<?> supportedSizes, CameraBridgeViewBase.ListItemAccessor accessor, int surfaceWidth, int surfaceHeight)
          This helper method can be called by subclasses to select camera preview size.
protected abstract  boolean connectCamera(int width, int height)
          This method is invoked shall perform concrete operation to initialize the camera.
protected  void deliverAndDrawFrame(Mat frame)
          This method shall be called by the subclasses when they have valid object and want it to be delivered to external client (via callback) and then displayed on the screen.
 void disableFpsMeter()
           
 void disableView()
          This method is provided for clients, so they can disable camera connection and stop the delivery of frames even though the surface view itself is not destroyed and still stays on the scren
protected abstract  void disconnectCamera()
          Disconnects and release the particular camera object being connected to this surface view.
 void enableFpsMeter()
          This method enables label with fps value on the screen
 void enableView()
          This method is provided for clients, so they can enable the camera connection.
 void SetCaptureFormat(int format)
           
 void setCvCameraViewListener(CameraBridgeViewBase.CvCameraViewListener listener)
           
 void setMaxFrameSize(int maxWidth, int maxHeight)
          This method sets the maximum size that camera frame is allowed to be.
 void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3)
           
 void surfaceCreated(SurfaceHolder holder)
           
 void surfaceDestroyed(SurfaceHolder holder)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mCameraIndex

protected int mCameraIndex

mEnabled

protected boolean mEnabled

mFpsMeter

protected FpsMeter mFpsMeter

mFrameHeight

protected int mFrameHeight

mFrameWidth

protected int mFrameWidth

mMaxHeight

protected int mMaxHeight

mMaxWidth

protected int mMaxWidth

mPreviewFormat

protected int mPreviewFormat
Constructor Detail

CameraBridgeViewBase

public CameraBridgeViewBase(Context context,
                            AttributeSet attrs)

CameraBridgeViewBase

public CameraBridgeViewBase(Context context,
                            int cameraId)
Method Detail

AllocateCache

protected void AllocateCache()

calculateCameraFrameSize

protected Size calculateCameraFrameSize(java.util.List<?> supportedSizes,
                                        CameraBridgeViewBase.ListItemAccessor accessor,
                                        int surfaceWidth,
                                        int surfaceHeight)
This helper method can be called by subclasses to select camera preview size. It goes over the list of the supported preview sizes and selects the maximum one which fits both values set via setMaxFrameSize() and surface frame allocated for this view

Parameters:
supportedSizes -
surfaceWidth -
surfaceHeight -
Returns:

connectCamera

protected abstract boolean connectCamera(int width,
                                         int height)
This method is invoked shall perform concrete operation to initialize the camera. CONTRACT: as a result of this method variables mFrameWidth and mFrameHeight MUST be initialized with the size of the Camera frames that will be delivered to external processor.

Parameters:
width - - the width of this SurfaceView
height - - the height of this SurfaceView

deliverAndDrawFrame

protected void deliverAndDrawFrame(Mat frame)
This method shall be called by the subclasses when they have valid object and want it to be delivered to external client (via callback) and then displayed on the screen.

Parameters:
frame - - the current frame to be delivered

disableFpsMeter

public void disableFpsMeter()

disableView

public void disableView()
This method is provided for clients, so they can disable camera connection and stop the delivery of frames even though the surface view itself is not destroyed and still stays on the scren


disconnectCamera

protected abstract void disconnectCamera()
Disconnects and release the particular camera object being connected to this surface view. Called when syncObject lock is held


enableFpsMeter

public void enableFpsMeter()
This method enables label with fps value on the screen


enableView

public void enableView()
This method is provided for clients, so they can enable the camera connection. The actual onCameraViewStarted callback will be delivered only after both this method is called and surface is available


SetCaptureFormat

public void SetCaptureFormat(int format)

setCvCameraViewListener

public void setCvCameraViewListener(CameraBridgeViewBase.CvCameraViewListener listener)
Parameters:
listener -

setMaxFrameSize

public void setMaxFrameSize(int maxWidth,
                            int maxHeight)
This method sets the maximum size that camera frame is allowed to be. When selecting size - the biggest size which less or equal the size set will be selected. As an example - we set setMaxFrameSize(200,200) and we have 176x152 and 320x240 sizes. The preview frame will be selected with 176x152 size. This method is useful when need to restrict the size of preview frame for some reason (for example for video recording)

Parameters:
maxWidth - - the maximum width allowed for camera frame.
maxHeight - - the maximum height allowed for camera frame

surfaceChanged

public void surfaceChanged(SurfaceHolder arg0,
                           int arg1,
                           int arg2,
                           int arg3)

surfaceCreated

public void surfaceCreated(SurfaceHolder holder)

surfaceDestroyed

public void surfaceDestroyed(SurfaceHolder holder)

Official OpenCV 2.4 Documentation