This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CameraHandler { | |
private static final String TAG = CameraHandler.class.getSimpleName(); | |
public static final int IMAGE_WIDTH = 640; | |
public static final int IMAGE_HEIGHT = 480; | |
private static final int MAX_IMAGES = 1; | |
private CameraDevice mCameraDevice; | |
private CameraCaptureSession mCaptureSession; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ImagePreprocessor { | |
private static final boolean SAVE_PREVIEW_BITMAP = false; | |
private Bitmap rgbFrameBitmap; | |
private Bitmap croppedBitmap; | |
public ImagePreprocessor() { | |
this.croppedBitmap = Bitmap.createBitmap(224, 224, | |
Bitmap.Config.ARGB_8888); | |
this.rgbFrameBitmap = Bitmap.createBitmap(CameraHandler.IMAGE_WIDTH, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Begin a still image capture | |
*/ | |
fun takePicture() { | |
if (cameraDevice == | |
null) { | |
Log.w(TAG, "Cannot capture image. Camera not initialized.") | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Execute a new capture request within the active session | |
*/ | |
private fun triggerImageCapture() { | |
try { | |
val captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE) | |
captureBuilder.addTarget(imageReader.getSurface()) | |
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<intent-filter> | |
<action android:name="android.intent.action.MAIN"/> | |
<category android:name="android.intent.category.IOT_LAUNCHER"/> | |
<category android:name="android.intent.category.DEFAULT"/> | |
</intent-filter> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imagePreprocessor = ImagePreprocessor() | |
cameraHandler = CameraHandler.getInstance() as CameraHandler | |
cameraHandler!!.initializeCamera( | |
this@ActivityClass, backgroundHandler, | |
this@ActivityClass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onImageAvailable(reader: ImageReader?) { | |
lateinit var bitmap: Bitmap | |
reader?.acquireNextImage().use | |
{ | |
image -> bitmap = imagePreprocessor?.preprocessImage(image)!! | |
} | |
runOnUiThread | |
{ | |
imageView.setImageBitmap(bitmap) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Student(var name: String, var regNo: Long, var gender: String, var address: String, var phNo: Long) | |
/** Equivalent Java reference | |
Student std1 = new Student("Ashwin", 111712104013L, "Male", "Chennai", 4353453453L ) | |
**/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Test { | |
internal fun demoMethod() { | |
println("demoMethod for singleton") | |
} | |
} | |
/** Equivalent Java Reference | |
Test.INSTANCE.demoMethod(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test | |
{ | |
companion object { | |
val num: Int = 1 | |
fun call() | |
{ | |
println("Calling companion") | |
} | |
} | |
} |
OlderNewer