public abstract class VisualizeCamera2Activity extends SimpleCamera2Activity
SimpleCamera2Activity which adds visualization and hooks for image
processing. Video frames are automatically converted into a format which can be processed by
computer vision. Optionally multiple threads can be generated so that video frames are
processed concurrently. The input image is automatically converted into a Bitmap image if
requested. If multiple threads are being used the user can toggle if they want visualization
to be shown if an old image finished being processed after a newer one.
Must call startCamera(ViewGroup, TextureView) in onCreate().
To customize it's behavior override the following functions:
Useful variables
SimpleCamera2Activity| Modifier and Type | Class and Description |
|---|---|
protected static class |
VisualizeCamera2Activity.BoofImage
Data related to converting between Image and BoofCV data types
All class data is owned by the lock
|
class |
VisualizeCamera2Activity.DisplayView
Custom view for visualizing results
|
SimpleCamera2Activity.CameraState| Modifier and Type | Field and Description |
|---|---|
protected android.graphics.Bitmap |
bitmap |
protected java.lang.Object |
bitmapLock |
protected byte[] |
bitmapTmp |
protected VisualizeCamera2Activity.DisplayView |
displayView |
protected android.graphics.Matrix |
imageToView
Stores the transform from the video image to the view it is displayed on.
|
protected java.lang.Object |
lockTiming |
protected boofcv.misc.MovingAverage |
periodConvert |
protected boolean |
showBitmap |
protected boolean |
stretchToFill |
protected int |
targetResolution |
protected android.view.TextureView |
textureView |
protected java.util.concurrent.ThreadPoolExecutor |
threadPool |
protected java.util.concurrent.LinkedBlockingQueue |
threadQueue |
protected long |
timeOfLastUpdated |
protected static int |
TIMING_WARM_UP |
protected int |
totalConverted |
protected android.graphics.Matrix |
viewToImage |
protected boolean |
visualizeOnlyMostRecent |
cameraToDisplayDensity, displayMetrics, mTextureView, mView, verbose, viewHeight, viewWidthDEFAULT_KEYS_DIALER, DEFAULT_KEYS_DISABLE, DEFAULT_KEYS_SEARCH_GLOBAL, DEFAULT_KEYS_SEARCH_LOCAL, DEFAULT_KEYS_SHORTCUT, FOCUSED_STATE_SET, RESULT_CANCELED, RESULT_FIRST_USER, RESULT_OKACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, COMPANION_DEVICE_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, FINGERPRINT_SERVICE, HARDWARE_PROPERTIES_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_STATS_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, PRINT_SERVICE, RECEIVER_VISIBLE_TO_INSTANT_APPS, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SHORTCUT_SERVICE, STORAGE_SERVICE, STORAGE_STATS_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_CLASSIFICATION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_AWARE_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE| Constructor and Description |
|---|
VisualizeCamera2Activity() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
onCameraResolutionChange(int cameraWidth,
int cameraHeight,
int sensorOrientation)
Called when the camera's resolution has changed.
|
protected void |
onCreate(android.os.Bundle savedInstanceState) |
protected void |
onDrawFrame(android.view.SurfaceView view,
android.graphics.Canvas canvas)
Renders the visualizations.
|
protected void |
processFrame(android.media.Image image)
Process a single frame from the video feed.
|
protected abstract void |
processImage(boofcv.struct.image.ImageBase image)
Where all the image processing happens.
|
protected int |
selectResolution(int widthTexture,
int heightTexture,
android.util.Size[] resolutions)
Selects a resolution which has the number of pixels closest to the requested value
|
protected void |
setImageType(boofcv.struct.image.ImageType type,
boofcv.alg.color.ColorFormat colorFormat)
Changes the type of image the camera frame is converted to
|
void |
setThreadPoolSize(int threads)
Specifies the number of threads in the thread-pool.
|
protected void |
startCamera() |
protected void |
startCamera(android.view.ViewGroup layout,
android.view.TextureView view) |
protected void |
startCameraTexture(android.view.TextureView view)
After this function is called the camera will be start.
|
protected void |
startCameraView(android.view.View view) |
protected static void |
videoToDisplayMatrix(int cameraWidth,
int cameraHeight,
int cameraRotation,
int displayWidth,
int displayHeight,
int displayRotation,
boolean stretchToFill,
android.graphics.Matrix imageToView) |
cameraNominalFov, closeCamera, configureCamera, handleCameraOpenException, handleNoCameraSelected, handleOnImageAvailableException, onCameraDisconnected, onCameraOpened, onPause, onResume, openCamera, reopenCameraAtResolution, selectCamera, setVerboseaddContentView, attachBaseContext, closeContextMenu, closeOptionsMenu, createPendingResult, dismissDialog, dismissKeyboardShortcutsHelper, dispatchGenericMotionEvent, dispatchKeyEvent, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, dump, enterPictureInPictureMode, enterPictureInPictureMode, findViewById, finish, finishActivity, finishActivityFromChild, finishAffinity, finishAfterTransition, finishAndRemoveTask, finishFromChild, getActionBar, getApplication, getCallingActivity, getCallingPackage, getChangingConfigurations, getComponentName, getContentScene, getContentTransitionManager, getCurrentFocus, getFragmentManager, getIntent, getLastNonConfigurationInstance, getLayoutInflater, getLoaderManager, getLocalClassName, getMaxNumPictureInPictureActions, getMediaController, getMenuInflater, getParent, getParentActivityIntent, getPreferences, getReferrer, getRequestedOrientation, getSearchEvent, getSystemService, getTaskId, getTitle, getTitleColor, getVoiceInteractor, getVolumeControlStream, getWindow, getWindowManager, hasWindowFocus, invalidateOptionsMenu, isActivityTransitionRunning, isChangingConfigurations, isChild, isDestroyed, isFinishing, isImmersive, isInMultiWindowMode, isInPictureInPictureMode, isLocalVoiceInteractionSupported, isTaskRoot, isVoiceInteraction, isVoiceInteractionRoot, managedQuery, moveTaskToBack, navigateUpTo, navigateUpToFromChild, onActionModeFinished, onActionModeStarted, onActivityReenter, onActivityResult, onApplyThemeResource, onAttachedToWindow, onAttachFragment, onBackPressed, onChildTitleChanged, onConfigurationChanged, onContentChanged, onContextItemSelected, onContextMenuClosed, onCreate, onCreateContextMenu, onCreateDescription, onCreateDialog, onCreateDialog, onCreateNavigateUpTaskStack, onCreateOptionsMenu, onCreatePanelMenu, onCreatePanelView, onCreateThumbnail, onCreateView, onCreateView, onDestroy, onDetachedFromWindow, onEnterAnimationComplete, onGenericMotionEvent, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyShortcut, onKeyUp, onLocalVoiceInteractionStarted, onLocalVoiceInteractionStopped, onLowMemory, onMenuItemSelected, onMenuOpened, onMultiWindowModeChanged, onMultiWindowModeChanged, onNavigateUp, onNavigateUpFromChild, onNewIntent, onOptionsItemSelected, onOptionsMenuClosed, onPanelClosed, onPictureInPictureModeChanged, onPictureInPictureModeChanged, onPostCreate, onPostCreate, onPostResume, onPrepareDialog, onPrepareDialog, onPrepareNavigateUpTaskStack, onPrepareOptionsMenu, onPreparePanel, onProvideAssistContent, onProvideAssistData, onProvideKeyboardShortcuts, onProvideReferrer, onRequestPermissionsResult, onRestart, onRestoreInstanceState, onRestoreInstanceState, onRetainNonConfigurationInstance, onSaveInstanceState, onSaveInstanceState, onSearchRequested, onSearchRequested, onStart, onStateNotSaved, onStop, onTitleChanged, onTouchEvent, onTrackballEvent, onTrimMemory, onUserInteraction, onUserLeaveHint, onVisibleBehindCanceled, onWindowAttributesChanged, onWindowFocusChanged, onWindowStartingActionMode, onWindowStartingActionMode, openContextMenu, openOptionsMenu, overridePendingTransition, postponeEnterTransition, recreate, registerForContextMenu, releaseInstance, removeDialog, reportFullyDrawn, requestDragAndDropPermissions, requestPermissions, requestShowKeyboardShortcuts, requestVisibleBehind, requestWindowFeature, runOnUiThread, setActionBar, setContentTransitionManager, setContentView, setContentView, setContentView, setDefaultKeyMode, setEnterSharedElementCallback, setExitSharedElementCallback, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setFinishOnTouchOutside, setImmersive, setIntent, setMediaController, setPictureInPictureParams, setProgress, setProgressBarIndeterminate, setProgressBarIndeterminateVisibility, setProgressBarVisibility, setRequestedOrientation, setResult, setResult, setSecondaryProgress, setShowWhenLocked, setTaskDescription, setTheme, setTitle, setTitle, setTitleColor, setTurnScreenOn, setVisible, setVolumeControlStream, setVrModeEnabled, shouldShowRequestPermissionRationale, shouldUpRecreateTask, showAssist, showDialog, showDialog, showLockTaskEscapeMessage, startActionMode, startActionMode, startActivities, startActivities, startActivity, startActivity, startActivityForResult, startActivityForResult, startActivityFromChild, startActivityFromChild, startActivityFromFragment, startActivityFromFragment, startActivityIfNeeded, startActivityIfNeeded, startIntentSender, startIntentSender, startIntentSenderForResult, startIntentSenderForResult, startIntentSenderFromChild, startIntentSenderFromChild, startLocalVoiceInteraction, startLockTask, startManagingCursor, startNextMatchingActivity, startNextMatchingActivity, startPostponedEnterTransition, startSearch, stopLocalVoiceInteraction, stopLockTask, stopManagingCursor, takeKeyEvents, triggerSearch, unregisterForContextMenuapplyOverrideConfiguration, getAssets, getResources, getThemebindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getSharedPreferences, getSystemServiceName, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setWallpaper, setWallpaper, startForegroundService, startInstrumentation, startService, stopService, unbindService, unregisterReceivergetColor, getColorStateList, getDrawable, getString, getString, getSystemService, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacksprotected android.view.TextureView textureView
protected VisualizeCamera2Activity.DisplayView displayView
protected final java.lang.Object bitmapLock
protected android.graphics.Bitmap bitmap
protected byte[] bitmapTmp
protected java.util.concurrent.LinkedBlockingQueue threadQueue
protected java.util.concurrent.ThreadPoolExecutor threadPool
protected android.graphics.Matrix imageToView
protected android.graphics.Matrix viewToImage
protected int targetResolution
protected boolean showBitmap
protected boolean stretchToFill
protected boolean visualizeOnlyMostRecent
protected volatile long timeOfLastUpdated
protected static final int TIMING_WARM_UP
protected final java.lang.Object lockTiming
protected int totalConverted
protected final boofcv.misc.MovingAverage periodConvert
protected void onCreate(android.os.Bundle savedInstanceState)
onCreate in class SimpleCamera2Activitypublic void setThreadPoolSize(int threads)
protected void startCamera(@NonNull
android.view.ViewGroup layout,
@Nullable
android.view.TextureView view)
layout - Where the visualization overlay will be placed inside ofview - If not null then this will be used to display the camera preview.protected void startCameraTexture(@Nullable
android.view.TextureView view)
SimpleCamera2ActivitystartCameraTexture in class SimpleCamera2Activityview - The view the camera is displayed inside or null if not displayedprotected void startCameraView(@Nullable
android.view.View view)
startCameraView in class SimpleCamera2Activityprotected void startCamera()
startCamera in class SimpleCamera2Activityprotected int selectResolution(int widthTexture,
int heightTexture,
android.util.Size[] resolutions)
selectResolution in class SimpleCamera2ActivitywidthTexture - Width of the texture the preview is displayed inside of. <= 0 if no viewheightTexture - Height of the texture the preview is displayed inside of. <= 0 if no viewresolutions - array of possible resolutionsprotected void onCameraResolutionChange(int cameraWidth,
int cameraHeight,
int sensorOrientation)
SimpleCamera2ActivityonCameraResolutionChange in class SimpleCamera2Activityprotected static void videoToDisplayMatrix(int cameraWidth,
int cameraHeight,
int cameraRotation,
int displayWidth,
int displayHeight,
int displayRotation,
boolean stretchToFill,
android.graphics.Matrix imageToView)
protected void setImageType(boofcv.struct.image.ImageType type,
boofcv.alg.color.ColorFormat colorFormat)
protected void processFrame(android.media.Image image)
SimpleCamera2ActivityprocessFrame in class SimpleCamera2Activityprotected abstract void processImage(boofcv.struct.image.ImageBase image)
image - The image which is to be processed. The image is owned by this function until
it returns. After that the image and all it's data will be recycled. DO NOT
SAVE A REFERENCE TO IT.protected void onDrawFrame(android.view.SurfaceView view,
android.graphics.Canvas canvas)